简体   繁体   中英

How to execute next stage in Azure Devops Release pipeline?

In Azure devops, Release pipeline, I am trying to run a stage after two different stage as below. I am facing issue in running the API-test stage.

  1. Dev stage is auto triggered.
  2. QA stage is manual triggered.
  3. API-test is needs to run either Dev/QA is successful.

在此处输入图像描述

Expected:

API-test needs to run if either Dev or QA stage is successful.

Actual:

API-test stage is not triggered when Dev stage is successful.

Kindly let me know the required configuration.

Besides of duplicating the API-Test stage, another workaround is to use Update Release Environment rest api . See below steps:

1, Set API-Test stage only be auto triggered after Dev stage.

在此处输入图像描述

2, Go the security page of your release edit page. 在此处输入图像描述

Set the Manage deployments to allow for account yourProjectname Build Service(Your Organization) . This persmission will allow you to update the release environment in the release pipeline.

在此处输入图像描述

3, Go to QA stage-->In the Agent job section-->Check Allow scripts to access the OAuth token . This setting will allow you to use the accesstoken in the release pipeline.

在此处输入图像描述

4, After above preparation, you can now add a script task at the end of QA stage to call the release rest api. See below example in powershell task:

#Get releaseresponse
$Releaseurl= "https://vsrm.dev.azure.com/{yourOrg}/$(System.TeamProject)/_apis/Release/releases/$(Release.ReleaseId)?api-version=6.0-preview.8" 

$releaseresponse = Invoke-RestMethod -Method Get -Headers @{Authorization = "Bearer $(system.accesstoken)"} -ContentType application/json -Uri $Releaseurl

#Get the environment ID of API-Test stage from the release response:
$id = $releaseresponse.environments |  Where-Object{$_.name -match "API-Test"} | select id

#Create the JSON body for the deployment:
$deploymentbody = @" 
{"status": "inprogress"} 
"@
#Invoke the REST method to trigger the deployment to API-Test stage:
$DeployUrl = "https://vsrm.dev.azure.com/{yourOrg}/$(System.TeamProject)/_apis/release/releases/$(Release.ReleaseId)/environments/$($id.id)?api-version=6.0-preview.7" 

$DeployRelease = Invoke-RestMethod -Method Patch -ContentType application/json -Uri $DeployUrl -Headers @{Authorization = "Bearer $(system.accesstoken)"} -Body $deploymentbody

Above scripts first call get Release rest api to get the environment id of API-Test stage. Then call the update release environment rest api to trigger the deployment to API-Test.

So that above script can achieve the API-Test stage be triggered after manually Deployment to QA stage is successfully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM