我们在Azure DevOps中有产品级别的项目,最后统计我们有94个产品。我需要找到一种方法来为所有项目创建相同的迭代(专门用于研发时间(
使用Postman我尝试了这个:
POST https://dev.azure.com/OrgName/Project1/_apis/wit/classificationnodes/Iterations?api-version=5.0
这个作为主体:
{"name": "Research and Development 2020-11-02", "attributes": {"startDate": "2020-11-02T00:00:00Z","finishDate": "2020-11-06T00:00:00Z"}}
它在一定程度上起到了作用,因为它为我的一个项目创建了一个迭代,但它最终在项目中丢失了(直到我在项目设置中查找它,它才作为列出的sprint出现在积压页面上(。
有没有一种方法可以让我使用Postman循环浏览我的所有DevOps项目,以及我如何放下迭代/冲刺,使其可见,而无需在项目设置中跟踪它?
有没有一种方法可以使用Postman循环我的所有DevOps项目,以及我如何放下迭代/冲刺,使其可见,而无需在项目设置中跟踪它?
下面是一个powershell示例:
$token = "PAT"
$url="https://dev.azure.com/{Organization}/_apis/projects?api-version=6.0"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json
ForEach( $project in $response.value.name )
{
$url1="https://dev.azure.com/{Organization name}/$($project)/_apis/wit/classificationnodes/Iterations?api-version=5.0"
$JSON = @'
{
"name": "Research9", "attributes": {"startDate": "2020-11-02T00:00:00Z","finishDate": "2020-11-06T00:00:00Z"}
}
'@
$response1 = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json
ForEach($id in $response1.identifier)
{
echo $id
echo $project
$url2="https://dev.azure.com/{Organization name}/$($project)/_apis/work/teamsettings/iterations?api-version=6.0"
$body = "{
`"id`": `"$id`"
}"
$response2 = Invoke-RestMethod -Uri $url2 -Headers @{Authorization = "Basic $token"} -Method Post -Body $body -ContentType application/json
}
}
解释:
此示例可以遍历所有项目,同时创建迭代,并最终将迭代添加到团队中
第一个Rest API用于列出项目名称。
第二个剩余API用于创建迭代。
Third Rest API用于将迭代添加到默认团队。然后你可以在Backlog中看到迭代。
在这种情况下,它是可见的,而无需在项目设置中跟踪它。
更新:
请尝试以下脚本:
$token = "PAT"
$url="https://dev.azure.com/{Organization Name}/_apis/projects?api-version=6.0"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json
$ExcludeList = "Docker", "Azure","ProjectNAME"
ForEach( $project in $response.value.name )
{
if ($ExcludeList | Where-Object {$project -like $_}) {
echo $project
echo "No Add"
}
else{
$url1="https://dev.azure.com/{Organization name}/$($project)/_apis/wit/classificationnodes/Iterations?api-version=5.0"
$JSON = @'
{
"name": "Research10", "attributes": {"startDate": "2020-11-02T00:00:00Z","finishDate": "2020-11-06T00:00:00Z"}
}
'@
$response1 = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json
ForEach($id in $response1.identifier)
{
echo $id
echo $project
$url2="https://dev.azure.com/{Organization Name}/$($project)/_apis/work/teamsettings/iterations?api-version=6.0"
$body = "{
`"id`": `"$id`"
}"
$response2 = Invoke-RestMethod -Uri $url2 -Headers @{Authorization = "Basic $token"} -Method Post -Body $body -ContentType application/json
}
}
}
Rest API不支持排除项目(基于名称(。但在Powershell中,您可以通过判断项目名称来排除这些项目。
$ExcludeList = "Docker", "Azure"
if ($ExcludeList | Where-Object {$project -like $_}) {
echo $project
echo "No Add"
}
如果项目名称在列表中,则项目将不会创建迭代。