[英]How to execute next stage in Azure Devops Release pipeline?
除了复制 API-Test 阶段之外,另一个解决方法是使用Update Release Environment rest api 。 请参见以下步骤:
1、设置API-Test阶段仅在Dev阶段后自动触发。
设置管理部署以允许帐户yourProjectname Build Service(Your Organization) 。 此权限将允许您更新发布管道中的发布环境。
3、Go到QA阶段-->在Agent job部分-->勾选Allow scripts to access the OAuth token
。 此设置将允许您在发布管道中使用访问令牌。
4、经过以上准备,现在可以在QA阶段的最后添加一个脚本任务来调用发布rest api。 请参阅 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
上述脚本首先调用get Release rest api获取 API-Test 阶段的环境 id。 然后调用更新发布环境rest api触发部署到API-Test。
这样上面的脚本就可以实现手动部署到QA阶段成功后触发API-Test阶段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.