Azure devops 发布管道触发器

Azure devops Release pipeline Trigger

我已经设置了应用程序构建发布管道和测试自动化发布管道 separate.Currently 只要创建了构建然后测试自动化就会启动,这是错误的,因为构建工件刚刚发布但尚未部署这将由发布管道完成。 所以我正在寻找一种解决方案,我可以将触发器添加到测试发布管道,它将检查构建发布管道是否已完成并将代码部署到环境中。

如果你在一个 yml 文件中有这个,你可以在 buildStagedeployStagecondition 上使用 dependsOn 来获取 [=15= 中前一阶段的成功状态]阶段

stages:
- stage: 'AutomationTestsStage'
  dependsOn:
  - buildStage
  - deployStage
  condition: succeeded()

根据您的描述,您拥有三个管道,构建管道(构建和发布工件)、应用程序发布管道和测试自动化发布管道。您已经设置了一个 CD 触发器,它将在管道完成后一起触发发布管道。但是你希望流水线运行的顺序是构建流水线->应用发布流水线->测试自动化发布管道,对吗?

So I am looking for a solution where I can add the trigger to the test release pipeline where It will check build release pipeline is completed & code is deployed to the environment.

作为解决方法,我们需要打开测试自动化发布管道定义并禁用CD触发器,然后打开应用发布流水线,在作业末尾添加任务权shell并调用REST API触发发布流水线(测试自动化发布流水线)

功率shell脚本:

$token = "{PAT}"   
$url = "https://vsrm.dev.azure.com/{Org name}/{Project name}/_apis/Release/releases?api-version=5.0"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))


$JSON = @"
{
  "definitionId": {test automation release pipeline definition ID}
}
"@

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -ContentType application/json -body $JSON

}

此外,我们需要将PowerShell条件设为Only when all previous tasks have succeeded,如下图

现在,它将运行在build release pipeline is completed & code is deployed to the environment

之后发布测试自动化发布管道