[英]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.在 Azure devops,发布管道中,我试图在如下两个不同阶段之后运行一个阶段。 I am facing issue in running the API-test stage.
我在运行 API 测试阶段时遇到问题。
Expected:预期的:
API-test needs to run if either Dev or QA stage is successful.如果开发或 QA 阶段成功,则需要运行 API 测试。
Actual:实际的:
API-test stage is not triggered when Dev stage is successful.开发阶段成功时不会触发 API 测试阶段。
Kindly let me know the required configuration.请让我知道所需的配置。
Besides of duplicating the API-Test stage, another workaround is to use Update Release Environment rest api .除了复制 API-Test 阶段之外,另一个解决方法是使用Update Release Environment rest api 。 See below steps:
请参见以下步骤:
1, Set API-Test stage only be auto triggered after Dev stage. 1、设置API-Test阶段仅在Dev阶段后自动触发。
2, Go the security page of your release edit page. 2、Go你的发布编辑页面的安全页面。
Set the Manage deployments to allow for account yourProjectname Build Service(Your Organization) .设置管理部署以允许帐户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
. 3、Go到QA阶段-->在Agent job部分-->勾选
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. 4、经过以上准备,现在可以在QA阶段的最后添加一个脚本任务来调用发布rest api。 See below example in powershell task:
请参阅 powershell 任务中的以下示例:
#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.上述脚本首先调用get Release rest api获取 API-Test 阶段的环境 id。 Then call the update release environment rest api to trigger the deployment to API-Test.
然后调用更新发布环境rest api触发部署到API-Test。
So that above script can achieve the API-Test stage be triggered after manually Deployment to QA stage is successfully.这样上面的脚本就可以实现手动部署到QA阶段成功后触发API-Test阶段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.