skip to Main Content

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

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search