admin管理员组文章数量:1391968
I need to trigger a yaml stage of the pipeline after completion of another pipeline completion.
I have a setup like this: the main pipeline has
stage1 -> stage2 -> stage3 -> stage4
After stage1
completes, it should trigger the testing yaml pipeline which is standalone and it has to get completed and once test yaml pipeline is completed successfully.
The next stages from stage2
should continue
I need to trigger a yaml stage of the pipeline after completion of another pipeline completion.
I have a setup like this: the main pipeline has
stage1 -> stage2 -> stage3 -> stage4
After stage1
completes, it should trigger the testing yaml pipeline which is standalone and it has to get completed and once test yaml pipeline is completed successfully.
The next stages from stage2
should continue
2 Answers
Reset to default 1If I understand it correctly, you're looking to have a single pipeline act as an orchestration that kicks off other pipelines and waits for them to complete before proceeding to the next stage. There are a few options available.
For starters, let's assume that stage1 triggers your pipeline using something like the Trigger Build extension or Azure DevOps REST API to queue the build. As we'll need to know the pipeline run id later, you'll need to create an output variable we can reference later:
- stage: stage1
jobs:
- job: job1
steps:
- ...
- pwsh: |
$buildId = "<value obtained from rest api or trigger build>"
write-host "##vso[task.setvariable variable=buildId;isoutput=true]$buildId"
name: captureId
Let's also assume that stage2 has a deployment
job:
- stage: stage2
dependsOn: stage1
jobs:
- deployment: deploy1
environment: stage2_environment
strategy:
runOnce:
deploy:
steps:
- ... deploy steps
Approvals + Checks: Invoke REST API (Synchronous)
You can use the "Approvals + Checks" feature to add a Invoke REST API check that polls the status of the build using the Azure DevOps REST API.
To set this up:
Create a generic service connection that contains the base URL of your Azure DevOps anization (
https://dev.azure/<name>
). The credentials defined here won't be used.On the Pipeline Environment for stage2, add a Invoke REST-API check. Specify the following:
- Service Connection:
- Headers:
{ "Authorization": "Bearer $(System.AccessToken)" }
- Method:
GET
- Url Suffix and parameters:
$(System.TeamProject)/_apis/build/builds/$(stage1.job1.captureId.buildId)?api-version=7.1
- Completion event: ApiResponse
- Success criteria:
eq(root['result'],'Succeeded')
- Timeout (minutes): 60
- Time between evaluations (minutes): 6
The above calls an Azure DevOps REST endpoint to get the details of the build. It evaluates the result
property of the build. Note the gate supports using variables from previous stages.
An important limitation with this approach is the ratio between Timeout and Time between evaluations must be 10:1. Anything more than this and it will fail due to throttling measures. For longer running pipelines, this will translate into longer evaluations, if the pipeline being monitored takes up to 240 minutes, the gate will check every 24 minutes. In my opinion, this is a long time to wait for a pipeline, but your mileage may vary.
Approvals + Checks (Asynchronous)
If you need better control of the retry interval, you can use either Invoke REST API or Invoke Function App check using the asynchronous callback model to call a custom Function App that monitors your pipeline. The asynchronous pattern is the recommended approach for custom gates. Your function app could in theory check the status of the pipeline as often as you like (assuming you don't exceed the API throttling limits ...roughly 200 times in 5 minutes).
If you'd consider using a Function App to monitor your pipeline, a cleaner approach would use the Function App to queue and monitor the pipeline as this would provide more re-use options for other pipelines.
Within the same YAML pipeline, after stage1 is completed successfully, there is no easy way to let the subsequent stage2 keep waiting until another pipeline is triggered and completed successfully.
The easiest way for your case is set up 3 pipelines:
- The first pipeline contains stage1.
- The second pipeline is "Testing yaml pipeline" which is triggered by the first pipeline via Pipelines resource trigger.
- The third pipeline contains stage2->stage3->stage4. It is triggered by the second pipeline via Pipelines resource trigger.
本文标签:
版权声明:本文标题:How to trigger a middle stage in yaml pipeline in Azure Devops after another pipeline's completion? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744673008a2618940.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论