Trigger Azure DevOps Release pipeline Stage from Spinnaker

763 Views Asked by At

I have created Release pipeline in Azure DevOps. I'm doing deployment inside spinnaker. Once Deployment got success/fail, the deployment status report should be come to Release pipeline stage in Azure DevOps.

How to achieve this? Is it possible with Rest-Api?

1

There are 1 best solutions below

0
On

It is possible to trigger azure devops release pipeline stage via rest api.

You can first use Releases-Create rest api to create a release.

 POST https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=6.1-preview.8

If you want to trigger a specific stage in this release. You can then use Releases - Update Release Environment.

PATCH https://vsrm.dev.azure.com/{organization}/{project}/_apis/Release/releases/{releaseId}/environments/{environmentId}?api-version=6.1-preview.7

See below example in powershell script: You can follow the steps here to get a personal access token.

$url = "https://vsrm.dev.azure.com/{org}/{proj}/_apis/release/releases?api-version=6.1-preview.8"

$PAT="Personnal Access Token"

$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))

$body = '{
  "definitionId": releaseDefinitionId,
 }'

#Create a release
$releaseInfo = Invoke-RestMethod -Uri $url -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)} -Method post -Body  $body -ContentType "application/json"

#Trigger a specific stage
$releaseId = $releaseInfo.id
$EnvironmentIds = $releaseInfo.environments | select id

#Trigger the second stage
$EnvUrl = "https://vsrm.dev.azure.com/{org}/{proj}/_apis/Release/releases/$($releaseId)/environments/$($EnvironmentIds[1].id)?api-version=6.1-preview.7"

$envBody='{
"status": "inProgress"
}'

Invoke-RestMethod -Uri $EnvUrl -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)} -Method patch -Body $envBody -ContentType "application/json"