1
votes

I have two pipelines in Azure Devops:

Pipeline A triggers on commits to master and produces a set of artifacts

Pipeline B triggers on successful completion of Pipeline A and consumes its artifacts

This all works correctly with just normal commits into master, however if I create a Branch Validation policy that enforces pull requests into master to run Pipeline A successfully, that PR pre-merge run of Pipeline A never triggers Pipeline B (which I want it to do for PRs as well, but its success is only optional for the PR).

If I add Pipeline B as a second branch validation directly (as an optional validation), it runs simultaneously with Pipeline A, but Pipeline B will not consume the correct artifacts because it isn't being triggered by the run it should consume from, and instead just pulls the latest artifacts available from the pipeline resource it expects to download from (which results in a race condition as Pipeline B when run simultaneously with Pipeline A will always finish first, so it downloads the N-1 artifact).

What I expected to work was:

In Pipeline B yaml:

resources:
  pipelines:
  - pipeline: pipelineA
    source: PipelineA
    trigger:
        branches:
          include : 
            - '*'

Then in the branch policy add a branch validation for Pipeline A, and a status check for Pipeline B with the status to check being 'VSTS-RM/PipelineA'. But it never triggers all the way through correctly.

Essentially what I want to do is this https://www.linkedin.com/pulse/end-to-end-pull-request-azure-devops-olivier-l%C3%A9ger where Pipeline B is just another yml build pipeline, not a release pipeline.

Is it not currently possible utilizing two build pipelines to do this?

1
How about the issue? Does the answer below resolved your question, If yes, you could Accept it as an Answer , so it could help other community members who get the same issues and we could archive this thread, thanks.Leo Liu-MSFT

1 Answers

0
votes

Run Sequential Build Pipelines as part of Pull Request Branch Policy in Azure Devops

If you want to add the Pipeline A and Pipeline B as branch validation, and Pipeline B consumes artifacts from Pipeline A, this does not seem to be supported by Azure devops yet.

Reason:

When Pipeline B is used as a branch validation alone, it will start immediately after the PR request is issued. If Pipeline B is not used as a branch validation, just as completion of Pipeline A, branch validation will not include Pipeline B, after Pipeline A is completed, PR will continue and will not wait and verify Pipeline B.

Workaround:

We could add the Pipeline B as one job in the Pipeline A:

stages:
- stage: PipelineA
  jobs:
  - job: PipelineA
    displayName: PipelineA
    pool:
     name: xxx
    steps:
      ...

- stage: PipelineB
  jobs:
  - job: PipelineB
    displayName: PipelineB
    pool:
     name: xxx
    steps:
      - download: current
        artifact: XX

In this case, we just need add the pipeline A as branch validation.

Please check the document Stage and Publish and download artifacts for some more details.

Hope this helps.