我想要在 Excel 文件中构建后更改的工作项目列表。
到目前为止我在这里:
$AzureDevOpsPAT = "**********************************"
$fromBuildId = "161"
$toBuildId = "176"
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
$uriAccount ="https://AzureDevOpsServerName/DefaultCollection/ProjectName/_apis/build/workitems?fromBuildId=$($fromBuildId)&toBuildId=$($toBuildId)&api-version=5.0"
$responsewe = Invoke-RestMethod -Uri $uriAccount -Method Get -Headers $AzureDevOpsAuthenicationHeader
$d1 = $responsewe.value | ConvertTo-Json write-host $d1
write-host $d1
另外,如何从这些工作项生成发行说明? 我也是 Powershell 和 DevOps 的新手,所以,任何想法都会受到赞赏。
我尝试先获取列表工作项的列表。
您可以使用下面的 Powershell 命令获取 csv 文件中构建之间的 WorkItems 输出:-
$PAT = "3fs6xxxxxxxxxxtyjs7cunwa"
$OrgName = "sid24desai0738"
$ProjectName = "AzureDevops"
$ApiVersion = "7.0"
$services = Invoke-RestMethod -Uri "https://dev.azure.com/$OrgName/$ProjectName/_apis/build/workitems?fromBuildId=1934&toBuildId=1937&api-version=7.1-preview.2" -Method Get -Headers @{Authorization=("Basic {0}" -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$PAT")))}
# Export $services to a CSV file
$services | Export-Csv -Path "C:\temp\log-function\File.csv" -NoTypeInformation
输出:-
参考:-
您已使用正确的 REST API 来获取构建之间的工作项。现在您需要将工作项导出到 Excel,并生成发行说明。
#create the file if it doesn't exist
$path = 'C:\temp\File.csv'
if(!(Test-Path $path)) {
New-Item -ItemType File -Path $path -Force
}
# Export $workitems to a CSV file
$response.value | Export-Csv -Path $path -NoTypeInformation
what information
。一旦您决定了这一点,您就可以循环遍历每个工作项并提取必要的信息。整个脚本示例:
$PAT = "yourpat"
$OrgName = "yourorgname"
$ProjectName = "projectname"
$buildid1 = "firstbuildid"
$buildid2 = "secondbuildid"
$headers = @{Authorization=("Basic {0}" -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$PAT")))}
#get the work items between builds
$response = Invoke-RestMethod -Uri "https://dev.azure.com/$OrgName/$ProjectName/_apis/build/workitems?fromBuildId=$buildid1&toBuildId=$buildid2&api-version=7.1-preview.2" -Method Get -Headers $headers
#output the response for a check
echo $response | ConvertTo-Json
#create the file if it doesn't exist
$path = 'C:\temp\File.csv'
if(!(Test-Path $path)) {
New-Item -ItemType File -Path $path -Force
}
# Export $workitems to a CSV file
$response.value | Export-Csv -Path $path -NoTypeInformation
# get the workitem id and url for the release note as an example
$releaseNotes = foreach ($workItem in $response.value) {
"Work Item ID: $($workItem.id)`nURL: $($workItem.url)`n---"
}
$releaseNotes | Out-File -FilePath 'c:\temp\ReleaseNotes.txt'