A few months ago, a colleague at work approached me and asked me about the easiest way to create release notes for a past release in Azure DevOps. Note that the CI/CD process in this case is implemented using Azure DevOps YAML pipelines.
There are of course different approaches to solve this challenge. Some of them depend on the chosen project management method. Assuming you work according to scrum and do a release and deployment after each iteration, you just query all work items of the corresponding iteration. However sometimes it’s not that easy as you may can imagine.
I found another simple approach that allows to query the work items between, for example, two deployment pipeline runs. Prerequisites for this approach are:
- Releases/deployments are performed by Azure DevOps YAML pipelines
- The affected pipeline runs (builds) are still available
- Work items were always linked on the pull requests
If all preconditions are met, the work items can be queried using PowerShell as follows.
$pat = "AZ_DEVOPS_SERVICES_PAT_HERE" # Scopes: Build (Read)
$base64encodedPAT = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("`:$pat"))
$response = Invoke-RestMethod -Method Get -Uri "https://dev.azure.com/{organization}/{project}/_apis/build/workitems?fromBuildId={fromBuildId}&toBuildId={toBuildId}&api-version=7.0" -Headers @{'Authorization' = "Basic $base64encodedPAT" }
# Additional PAT scope needed (Work Items (Read))
foreach ($wi in $response.value) {
$uri = "https://dev.azure.com/{organization}/{project}/_apis/wit/workItems/{0}?api-version=7.1-preview.3" -f $wi.id
$workItem = Invoke-RestMethod -Method Get -Uri $uri -Headers @{'Authorization' = "Basic $base64encodedPAT" }
Write-Host $workItem.fields.'System.WorkItemType'
Write-Host $workItem.fields.'System.Title'
Write-Host $workItem.url
Write-Host $workItem.id
Write-Host ""
}
Link to the documentation: Builds – Get Work Items Between Builds

Leave a comment