1
votes

I have build and release pipeline in Azure DevOps. That pipeline contains a three different stages namely STAGING, QA and PROD. So, after completion of deployment in QA slot I want to trigger PROD environment using REST API. So, Is that possible to do the same?

1
Do you really need it to be triggered with the REST API? Have you looked through the out-of-the-box triggers? docs.microsoft.com/en-us/azure/devops/pipelines/release/…Yan Sklyarenko
yeah, why dont you want to configure a stage trigger?4c74356b41
Yeah, as per requirements releases should be trigger by REST API.akoliya01
@4c74356b41 Because QA task will perform on VM. So I need to trigger PROD release from that VM using REST API.akoliya01

1 Answers

1
votes

It is impossible to do this in a single release pipeline. The release create api can only trigger the release pipeline to run, it cannot trigger a certain stage within the pipeline. As the stages in the release pipeline only support after release,after stage and manually.

To achieve your requirements, You will have to separate your prod stage from this release(Release A), which means you will create a new release pipeline(Release B) with the a single stage prod environment.

Then you can add a powershell task at the end of QA stage in release pipeline A to call the API to trigger Release B to deploy to Prod environment. below script is for example:

$releaseUrl ="https://vsrm.dev.azure.com/<organization>/<project>/_apis/release/releases?api-version=5.1"

$body = '{
  "definitionId": 4, # release definition id
  "description": "Creating prod release",
  "artifacts": [
    {
      "alias": "_NunitProject", #artifacts alias
      "instanceReference": {
        "id": "1367", #build id related to the artifacts
        "name": null
      }
    }
  ],
  "isDraft": false,
  "reason": "none",
  "manualEnvironments": null,
  }'


$result4 = Invoke-RestMethod -Uri $releaseUrl -Headers @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" } -Method post -Body $body -ContentType "application/json"