1

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
}
  • 1
    what is the question? the script didn't work? did you get an error? – Shayki Abramczyk Sep 21 '20 at 11:00
  • hi, i am looking for the right api to get all the work items associated with my release pipeline. i have edited the question now –  Sep 21 '20 at 12:39
  • Check this article: https://devblogs.microsoft.com/premier-developer/how-to-retrieve-all-work-items-associated-with-a-release-pipeline-using-azure-devops-api/ – Shayki Abramczyk Sep 21 '20 at 12:56
  • yes i have seen this, but my requirement requires me to call api from a powershell scripts... i was hoping if i can get direction in powershell as it seems there are multiple apis to run –  Sep 21 '20 at 13:21

3 Answers3

2

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
BijithA
  • 21
  • 2
0

Can anyone direct me to the correct api which needs to be called in order to get the workitems associated with my release pipeline.

You can use the REST API Builds - Get Build Work Items Refs

GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/workitems?api-version=5.1

Although it is suitable for build pipelines according to the REST API's name, in fact, it can also be used for release pipelines.

Jane Ma-MSFT
  • 4,461
  • 1
  • 6
  • 12
0

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}:

enter image description here

{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}:

enter image description here

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 #**************************.

LoLance
  • 25,666
  • 1
  • 39
  • 73