Jnavero
Jnavero

Reputation: 363

Azure devops: Check status release from other release

I have a release A that is published in an X environment. On the other hand, I have a release B that is published in environment Y.

The problem is I would like to know if I can check the status of release A in release B and so I can throw an error and not publish release B.

I don't know if it's possible to do this with powershell or similar.

Any idea or orientation?

Upvotes: 3

Views: 742

Answers (1)

bryanbcook
bryanbcook

Reputation: 18363

PowerShell script using the Azure DevOps REST API is your best bet for this. Your question is somewhat similar to this one.

You'll need to find the definition ids for the release A and environment Y. The best place to find these values is in the log output of the "Initialize Job" task from a deployment of Release A in Environment Y. Look for variables RELEASE_DEFINITIONID and RELEASE_ENVIRONMENTID.

Assuming the "classic" mode for Azure Pipelines (not YAML based):

  1. Enable "allow scripts to access oAuth token" checkbox for the 'agent phase' of the pipeline.enter image description here
  2. Add a PowerShell task and query the latest release for "release definition A" using the List Deployments Endpoint (see the linked answer for full example, simplified version below)
param()

$auth = "Bearer {0}" -f $env:SYSTEM_ACCESSTOKEN

$url =  "https://{0}{1}" -f $env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI $env:SYSTEM_TEAMPROJECTID
$url += "/release/deployments?definitionId=" + $your_release_definition_id
$url += "&definitionEnvironmentId=" + $your_environment_definition_id
$url += "&deploymentStatus=succeeded"
$url += "&queryOrder=descending"
$url += "&api-version=5.0"

$releaseA = Invoke-WebRequest $url -Headers @{Authorization=($authHeader)} | ConvertFrom-Json
  1. Inspect the status of the release and throw an error if it doesn't meet your criteria.

Alternatively, if this release is dependent on another release and they need to deploy together as a unit -- why not consider adding multiple artifacts to the release and deploy as a single release instead?

Upvotes: 2

Related Questions