Reputation:
In Azure DevOps, I have a CI pipeline which generates an artifact. As soon as the Pull Request gets approved, it triggers a release pipeline. In the release pipeline, I have added a PowerShell task to perform some REST API functions. I am trying to get all the work items associated with this release. and for that i used below api but i get page not found. Can anyone direct me to the correct api which needs to be called in order to get the workitems associated with my release pipeline.
/_apis/Release/releases/$releaseid/workitems?api-version=6.0
here is the powershell snippet which i am trying to call, here release id is called by defining the predefined variable in powershell task in release pipeline
Function GET-WORKRELEASE{
$AzureDevOpsPAT = "wiosoqn4x66brkkcntesttesttesta"
$OrganizationName = "thru"
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
$orz = "https://dev.azure.com/$($OrganizationName)/thru"
$d=''
$uriAccount = $orz + "/_apis/Release/releases/$releaseid/workitems?api-version=6.0"
$responsewe = Invoke-RestMethod -Uri $uriAccount -Method get -Headers $AzureDevOpsAuthenicationHeader
$d1 = $responsewe.value | ConvertTo-Json
write-host $d1
}
Upvotes: 1
Views: 1768
Reputation: 21
You may use following API: https://{organizationName}.vsrm.visualstudio.com/{project}/_apis/release/releases/{releaseid}/workitems?api-version=6.0-preview
You would need to modify snippet as below:
$AzureDevOpsPAT = "************************"
$OrganizationName = "YourOrgName"
$Project = "YourProject"
$releaseid=releaseID
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
$orz = "https://$($OrganizationName).vsrm.visualstudio.com/$($Project)"
$uriAccount = $orz + "/_apis/Release/releases/$($releaseid)/workitems?api-version=6.0-preview"
$responsewe = Invoke-RestMethod -Uri $uriAccount -Method get -Headers $AzureDevOpsAuthenicationHeader
$d1 = $responsewe.value | ConvertTo-Json
write-host $d1
Upvotes: 2
Reputation: 28126
The api to get Work Items related to the release pipeline
is not documented, it should be:
Get: https://vsrm.dev.azure.com/{OrgName}/{ProjectName}/_apis/Release/releases/{ReleaseId}/workitems?baseReleaseId={BaseReleaseId}&%24top=250&artifactAlias={ArtifactAlias}
{OrgName}
: Your organization name.
{ProjectName}
: Your corresponding project name.
{ReleaseId}
:
{BaseReleaseId}
: The last previous release that has a deployment,
BaseReleaseId = ReleaseId-1
in some cases. If ReleaseId is 12
, the BaseReleaseId is 11
in most cases.
{ArtifactAlias}
:
For more details you can check my another thread here.
And your PS script should be changed to:
$AzureDevOpsPAT = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$OrganizationName = "xxxxxx"
$ProjectName = "xxxxxx"
$ReleaseId = "xx"
$BaseReleaseId = "xx"
$ArtifactAlias = "_xxx"
#*********************************************************************************
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
$orz = "https://vsrm.dev.azure.com/$($OrganizationName)/$($ProjectName)"
$uriAccount = $orz + "/_apis/Release/releases/$($ReleaseId)/workitems?baseReleaseId=$($BaseReleaseId)&%24top=250&artifactAlias=$($ArtifactAlias)"
$responsewe = Invoke-RestMethod -Uri $urlAccount -Method Get -Headers $AzureDevOpsAuthenicationHeader
$d1 = $responsewe.value | ConvertTo-Json
write-host $d1
You only need to configure the variables above #**************************
.
Upvotes: 1