【问题标题】:How to execute next stage in Azure Devops Release pipeline?如何在 Azure Devops 发布管道中执行下一阶段?
【发布时间】:2020-07-24 01:26:56
【问题描述】:

在 Azure devops 发布管道中,我试图在两个不同阶段之后运行一个阶段,如下所示。我在运行 API 测试阶段时遇到问题。

  1. 开发阶段是自动触发的。
  2. QA 阶段是手动触发的。
  3. API-test 需要运行 Dev/QA 成功。

预期:

如果 Dev 或 QA 阶段成功,则需要运行 API 测试。

实际:

Dev 阶段成功时不会触发 API-test 阶段。

请告诉我所需的配置。

【问题讨论】:

  • 嗨,您有没有机会查看以下使用 rest api 的解决方法。进展如何?

标签: azure azure-devops


【解决方案1】:

除了复制 API-Test 阶段之外,另一种解决方法是使用Update Release Environment rest api。请参阅以下步骤:

1、设置API-Test阶段仅在Dev阶段后自动触发。

2,转到您的发布编辑页面的安全页面。

为帐户 yourProjectname Build Service(Your Organization)Manage deployments 设置为 allow。此权限将允许您更新发布管道中的发布环境。

3、进入QA阶段-->在Agent job部分-->勾选Allow scripts to access the OAuth token。此设置将允许您在发布管道中使用访问令牌。

4、经过以上准备,您现在可以在QA阶段结束添加一个脚本任务来调用release 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阶段。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    • 2021-03-25
    • 1970-01-01
    相关资源
    最近更新 更多