我正试图将迭代和日历假期添加到我的Azure DevOps项目中,但无法解决。
使用Azure DevOps CLI和一些PowerShell脚本代码,然后运行它,窗口立即关闭。在任何项目中都不会创建任何内容,也不会进行控制台编写:
Param
(
[string]$PAT = [my PAT],
[string]$Organization = [my organization],
[string]$Project = 'DevTeam',
[string]$TeamName = 'DevTeam Team',
[DateTime]$StartDate = Get-Date,
[int]$NumberOfSprints = 18
)
echo $PAT | az devops login --org $Organization
Write-Host '===Configuring connection to organization and Team Project'
az devops configure --defaults organization=$Organization project=$Project
For ($i=1; $i -le $NumberOfSprints; $i++)
{
$StartDateIteration = $StartDate.AddDays(($i - 1) * 14)
$FinishDateIteration = $StartDateIteration.AddDays(20)
$Sprint = $StartDateIteration + '-' + $FinishDateIteration
$createIteration = az boards iteration project create --name $Sprint --start-date $StartDateIteration --finish-date $FinishDateIteration --org $Organization --project $Project | ConvertFrom-Json
$addIteration = az boards iteration team add --id $createIteration.Identifier --team $TeamName --org $Organization --project $Project | ConvertFrom-Json
Write-Host $addIteration.name 'created on path'$addIteration.path
}
所以我找到了这个使用REST API的方法。我在Postman中为REST API快速编写了一些内容,但这也返回了一个错误:
预请求脚本:
var occurences = 18;
var start_date = "11/11/2020";
for(i=1; i <= occurences; i++){
var repeat_every = 21*i; //repeat every number of days/weeks/months
var first = new Date(start_date);
first.setDate( first.getDate() + repeat_every );
var last = new Date(first.setDate(first.getDate() - 1));
var name = first.toDateString() + "-" + last.toDateString();
pm.environment.set("first", first);
pm.environment.set("last", last);
pm.environment.set("name", name);
};
JSON POST主体到";dev.azure.com/[我的组织]/DevTeam/_apis/work/teamsettings/editions?api版本=6.0";
{
"id": [my identifier from "GET dev.azure.com/[my organization]/DevTeam/_apis/wit/classificationnodes/iterations?api-version=6.0],
"name": {{name}},
"path": "DevTeam\Iteration",
"attributes": {
"startDate": {{first}},
"finishDate": {{last}}
}
}
错误:
{
"$id": "1",
"innerException": null,
"message": "TF400898: An Internal Error Occurred. Activity Id: bbe88905-2083-47e2-9b2c-d87be87c4adb.",
"typeName": "Newtonsoft.Json.JsonReaderException, Newtonsoft.Json",
"typeKey": "JsonReaderException",
"errorCode": 0,
"eventId": 0
}
- 如何使其中任何一个成功运行
- 这会自动在日历上添加迭代吗?我们的想法是整合日历,让DevOps跟踪我们的工作时间和休息时间,这样我们就可以在冲刺计划中使用它
谢谢。
我想分享Rest API方法。
此Rest API:迭代-团队后迭代仅用于将迭代添加到团队。
如果您需要创建或更改现有迭代,则需要结合以下两个API:
创建新迭代:分类节点-创建或更新
更新现有迭代:分类节点-更新
以下是PowerShell脚本示例:
创建新的迭代并将迭代添加到团队中:
$token = "PAT"
$url="https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/wit/classificationnodes/Iterations?api-version=5.0"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$JSON = @'
{
"name": "kevin5 Iteration",
"attributes": {
"startDate": "2014-10-27T00:00:00Z",
"finishDate": "2014-10-31T00:00:00Z"
}
}
'@
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json
$IterationId = $response.identifier
echo $IterationId
$url2 = "https://dev.azure.com/{OrganizationName}/{ProjectName}/{TeamName}/_apis/work/teamsettings/iterations?api-version=6.0"
$body = "{
`"id`": `"$IterationId`"
}"
$response = Invoke-RestMethod -Uri $url2 -Headers @{Authorization = "Basic $token"} -Method Post -Body $body -ContentType application/json
更新现有迭代并将迭代添加到团队中:
$token = "PAT"
$url="https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/wit/classificationnodes/iterations/{IterationName}?api-version=5.0"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$JSON = @'
{
"name": "Edit Iteration",
"attributes": {
"startDate": "2014-10-27T00:00:00Z",
"finishDate": "2014-10-31T00:00:00Z"
}
}
'@
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method PATCH -Body $JSON -ContentType application/json
$IterationId = $response.identifier
echo $IterationId
$url2 = "https://dev.azure.com/{OrganizationName}/{ProjectName}/{TeamName}/_apis/work/teamsettings/iterations?api-version=6.0"
$body = "{
`"id`": `"$IterationId`"
}"
$response = Invoke-RestMethod -Uri $url2 -Headers @{Authorization = "Basic $token"} -Method Post -Body $body -ContentType application/json