|
| 1 | +function New-AzDoClassificationNode { |
| 2 | + <# |
| 3 | +.SYNOPSIS |
| 4 | + Creates a Classification Node in Azure DevOps. |
| 5 | +.DESCRIPTION |
| 6 | + Creates a Classification Node in Azure DevOps. This could be an area or an iteration. |
| 7 | +.EXAMPLE |
| 8 | + $Params = @{ |
| 9 | + CollectionUri = "https://dev.azure.com/cantoso" |
| 10 | + ProjectName = "Playground" |
| 11 | + StructureGroup = "areas" |
| 12 | + Name = "Area1" |
| 13 | + } |
| 14 | +
|
| 15 | + New-AzDoClassificationNode @Params |
| 16 | +
|
| 17 | + This example creates a Classification Node of the type 'areas' within the Project. |
| 18 | +.EXAMPLE |
| 19 | + $Params = @{ |
| 20 | + CollectionUri = "https://dev.azure.com/cantoso" |
| 21 | + ProjectName = "Playground" |
| 22 | + StructureGroup = "areas" |
| 23 | + Name = "Area1" |
| 24 | + Path = "Path1" |
| 25 | + } |
| 26 | +
|
| 27 | + New-AzDoClassificationNode @Params |
| 28 | +
|
| 29 | + This example creates a Classification Node of the type 'areas' within the specified path. |
| 30 | +.EXAMPLE |
| 31 | + $Params = @{ |
| 32 | + CollectionUri = "https://dev.azure.com/cantoso" |
| 33 | + ProjectName = "Playground" |
| 34 | + StructureGroup = "iterations" |
| 35 | + Name = "Iteration1" |
| 36 | + } |
| 37 | +
|
| 38 | + New-AzDoClassificationNode @Params |
| 39 | +
|
| 40 | + This example creates a Classification Node of the type 'iterations' within the Project. |
| 41 | +.EXAMPLE |
| 42 | + $Params = @{ |
| 43 | + CollectionUri = "https://dev.azure.com/cantoso" |
| 44 | + ProjectName = "Playground" |
| 45 | + StructureGroup = "iterations" |
| 46 | + Name = "Iteration1" |
| 47 | + Path = "Path1" |
| 48 | + startDate = "10//701001 00:00:00 |
| 49 | + finishDate = "10//701008 00:00:00 |
| 50 | + } |
| 51 | +
|
| 52 | + New-AzDoClassificationNode @Params |
| 53 | +
|
| 54 | + This example creates a Classification Node of the type 'iterations' within the specified path, it is also possible to use a start and finish date of the iteration by adding the optional parameters 'startDate' and 'finishDate'. |
| 55 | +.OUTPUTS |
| 56 | + [PSCustomObject]@{ |
| 57 | + CollectionUri = $CollectionUri |
| 58 | + ProjectName = $ProjectName |
| 59 | + Id = $_.id |
| 60 | + Identifier = $_.identifier |
| 61 | + Name = $_.name |
| 62 | + StructureType = $_.structureType |
| 63 | + HasChildren = $_.hasChildren |
| 64 | + Path = $_.path |
| 65 | + Links = $_._links |
| 66 | + Url = $_.url |
| 67 | + } |
| 68 | +.NOTES |
| 69 | +#> |
| 70 | + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] |
| 71 | + param ( |
| 72 | + # Collection Uri of the organization |
| 73 | + [Parameter(Mandatory, ValueFromPipelineByPropertyName)] |
| 74 | + [ValidateScript({ Validate-CollectionUri -CollectionUri $_ })] |
| 75 | + [string] |
| 76 | + $CollectionUri, |
| 77 | + |
| 78 | + # Name of the project where the new repository has to be created |
| 79 | + [Parameter(Mandatory, ValueFromPipelineByPropertyName)] |
| 80 | + [string] |
| 81 | + $ProjectName, |
| 82 | + |
| 83 | + # Name of the project where the new repository has to be created |
| 84 | + [Parameter(Mandatory, ValueFromPipelineByPropertyName)] |
| 85 | + [string] |
| 86 | + $StructureGroup, |
| 87 | + |
| 88 | + # Path of the classification node (optional) |
| 89 | + [Parameter(ValueFromPipelineByPropertyName)] |
| 90 | + [string] |
| 91 | + $Path, |
| 92 | + |
| 93 | + # Name of the classification node |
| 94 | + [Parameter(Mandatory, ValueFromPipelineByPropertyName)] |
| 95 | + [string] |
| 96 | + $Name, |
| 97 | + |
| 98 | + # Start date of the iteration (optional) |
| 99 | + [Parameter(ValueFromPipelineByPropertyName)] |
| 100 | + [string] |
| 101 | + $startDate, |
| 102 | + |
| 103 | + # Finish date of the iteration (optional) |
| 104 | + [Parameter(ValueFromPipelineByPropertyName)] |
| 105 | + [string] |
| 106 | + $finishDate |
| 107 | + ) |
| 108 | + |
| 109 | + begin { |
| 110 | + Write-Verbose "Starting function: New-AzDoClassificationNode" |
| 111 | + } |
| 112 | + |
| 113 | + process { |
| 114 | + $ProjectId = (Get-AzDoProject -CollectionUri $CollectionUri -ProjectName $ProjectName).Projectid |
| 115 | + |
| 116 | + if ($Path) { |
| 117 | + $uri = "$CollectionUri/$ProjectName/_apis/wit/classificationnodes/$StructureGroup/$Path" |
| 118 | + } else { |
| 119 | + $uri = "$CollectionUri/$ProjectName/_apis/wit/classificationnodes/$StructureGroup" |
| 120 | + } |
| 121 | + |
| 122 | + $params = @{ |
| 123 | + uri = $uri |
| 124 | + version = "7.2-preview.2" |
| 125 | + Method = 'POST' |
| 126 | + } |
| 127 | + |
| 128 | + if ($StructureGroup -eq 'areas') { |
| 129 | + $body = @{ |
| 130 | + name = $Name |
| 131 | + } |
| 132 | + } |
| 133 | + if ($StructureGroup -eq 'iterations') { |
| 134 | + $body = @{ |
| 135 | + name = $Name |
| 136 | + attributes = @{ |
| 137 | + startDate = $startDate |
| 138 | + finishDate = $finishDate |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + |
| 144 | + if ($PSCmdlet.ShouldProcess($ProjectName, "Create Classification Node named: $($PSStyle.Bold)$Name$($PSStyle.Reset)")) { |
| 145 | + try { |
| 146 | + $body | Invoke-AzDoRestMethod @params | ForEach-Object { |
| 147 | + [PSCustomObject]@{ |
| 148 | + CollectionUri = $CollectionUri |
| 149 | + ProjectName = $ProjectName |
| 150 | + Id = $_.id |
| 151 | + Identifier = $_.identifier |
| 152 | + Name = $_.name |
| 153 | + StructureType = $_.structureType |
| 154 | + HasChildren = $_.hasChildren |
| 155 | + Path = $_.path |
| 156 | + Links = $_._links |
| 157 | + Url = $_.url |
| 158 | + } |
| 159 | + } |
| 160 | + } catch { |
| 161 | + if ($_ -match 'is already in use by a different') { |
| 162 | + Write-Warning "Classification Node already exists within the path, trying to get it" |
| 163 | + $params.Method = 'GET' |
| 164 | + $params.uri = "$uri/$Name" |
| 165 | + Invoke-AzDoRestMethod @params | ForEach-Object { |
| 166 | + [PSCustomObject]@{ |
| 167 | + CollectionUri = $CollectionUri |
| 168 | + ProjectName = $ProjectName |
| 169 | + Id = $_.id |
| 170 | + Identifier = $_.identifier |
| 171 | + Name = $_.name |
| 172 | + StructureType = $_.structureType |
| 173 | + HasChildren = $_.hasChildren |
| 174 | + Path = $_.path |
| 175 | + Links = $_._links |
| 176 | + Url = $_.url |
| 177 | + } |
| 178 | + } |
| 179 | + } else { |
| 180 | + Write-AzDoError -message $_ |
| 181 | + } |
| 182 | + } |
| 183 | + } |
| 184 | + } |
| 185 | +} |
0 commit comments