0

Is it possible to trigger another pipeline from the pipeline completion trigger if there is a failure in the triggering pipeline? Seems there is no configuration/property available by default as per the documentation. Just wanted to check whether there is any possible way with the pipeline completion trigger.

3 Answers3

0

If the initial pipeline fails to trigger, all subsequent pipelines would logically fail to trigger. Try having your initial pipeline start with a stage that will never fail, and if that pipeline fails, you can set it to trigger the subsequent pipelines after the first one fails but gets triggered succesfully.

Joe
  • 1,316
  • 9
  • 17
  • Bit unclear to me. Let's say I have A (triggering pipeline) and B (triggered pipeline) pipelines. I need to trigger B with pipeline completion trigger irrespective of the status of pipeline A. i.e. pipeline A can be either successful or there can one or more failed steps as well. – Sahan Gunathilaka Jun 30 '22 at 18:58
  • 1
    There is one way to get this worked by using pipeline stages and Stage filers in the pipeline trigger. I guess Joe is suggesting that approach. Yeah! we can have one stage that will never fail and upon that stage, we can trigger the next pipeline we want :) – Sahan Gunathilaka Jun 30 '22 at 19:17
  • Thank you for the clue! My requirement is sorted now :) – Sahan Gunathilaka Jul 01 '22 at 16:27
  • Thats it, glad you understood – Joe Jul 15 '22 at 18:36
  • I've done it myself and asked the same question, this was my solution – Joe Jul 15 '22 at 18:36
0

Is it possible to trigger another pipeline from the pipeline completion trigger if there is a failure in the triggering pipeline?

There is no such configuration/property available to achieve trigger another pipeline from the pipeline completion trigger if there is a failure in the triggering pipeline.

To resole this issue, you could try to add powershell task to use the REST API Builds - Queue

POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=6.1-preview.7

You could check this thread for the detailed scripts.

And set this powershell task with condition Only when a previous task has failed:

enter image description here

In this case, regardless of whether the previous task fails, the REST API will be called at the end of the pipeline to trigger the build.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Thank you for the response, but I was looking a way to do so using just pipeline triggers. It is possible when we use stages in the triggering pipeline. :) – Sahan Gunathilaka Jul 01 '22 at 16:26
0

I was able to manage my requirement through the pipeline completion trigger itself. It is possible if we define stages in the triggering pipeline. I'm posting the answer if someone else looking for the same approach.

  1. Need to define the triggering pipeline definition with stages. Also, we need to make sure that at least one stage should be successful every time. I already have few stages defined and hence this is totally matching with my requirement.

    Triggering pipeline YAML definition: (pipeline name: pipeline1)

    trigger: none
    pr: none
    
    pool:
      vmImage: 'ubuntu-latest'
    
    stages:
      - stage: stage_1
        displayName: Stage-1
        jobs:
          - job: greeting
            displayName: Greeting
            steps:
              - script: |
                  echo "Hello world!"
                  exit 1
    
      - stage: stage_2
        displayName: Stage-2
        condition: always()
        jobs:
          - job: thanking
            displayName: Thanking
            steps:
              - script: |
                  echo "Thank you!"
    
  2. Define the pipeline completion trigger with stage filters for the triggered pipeline.

    Triggered pipeline YAML definition:

    trigger: none
    pr: none
    
    resources:
      pipelines:
        - pipeline: Pipeline_1
          source: pipeline1
          trigger:
            stages:
              - stage_2
    
    pool:
      vmImage: 'ubuntu-latest'
    
    jobs:
      - job: greeting
        steps:
          - script: |
              echo "Hello world!"
    

Then the triggered pipeline will be triggered irrespective to the stage_1 in the triggering pipeline since stage_2 will be kept successful in each run.

  • But this would trigger the triggered pipeline right away as soon as stage_1 in triggering pipeline completed, right? So, if the triggered pipeline depends on results from stage_2 of the triggering pipeline, you might run into a race condition here, isn't it? – Torben Knerr Sep 16 '22 at 08:43
  • @TorbenKnerr, please check my answer again. I've updated the stage filter in the triggered pipeline to use `stage_2` rather `stage_1`. There was a mistake when I posted. The requirement mentioned here is to trigger the triggered pipeline when `stage_2` in triggering pipeline is successful. That is the only stage that triggered pipeline looks into. – Sahan Gunathilaka Oct 25 '22 at 06:05