Search code examples
azureazure-devopsazure-pipelines

Azure Pipeline to trigger Pipeline using YAML


Attempting to trigger an Azure pipeline when another pipeline has been completed using a YAML. There's documentation indicating that you can add a pipeline resource with:

resources:   # types: pipelines | builds | repositories | containers | packages
  pipelines:
  - pipeline: string  # identifier for the pipeline resource
    connection: string  # service connection for pipelines from other Azure DevOps organizations
    project: string # project for the source; optional for current project
    source: string  # source defintion of the pipeline
    version: string  # the pipeline run number to pick the artifact, defaults to Latest pipeline successful across all stages
    branch: string  # branch to pick the artiafct, optional; defaults to master branch
    tags: string # picks the artifacts on from the pipeline with given tag, optional; defaults to no tags

However, I've been unable to figure out what the "source" means. For example, I have a pipeline called myproject.myprogram:

resources:
  pipelines:
  - pipeline: myproject.myprogram
    source: XXXXXXXX

Moreover, it's unclear how you'd build based a trigger based on this.

I know that this can be done from the web-GUI, but it should be possible to do this from a YAML.


Solution

  • For trigger of one pipeline from another azure official docs suggest this below solution. i.e. use pipeline triggers

    resources:
      pipelines:
      - pipeline: RELEASE_PIPELINE # any arbitrary name
        source: PIPELINE_NAME.    # name of the previous pipeline shown on azure UI portal
        trigger:
          branches:
            include:
            - dummy_branch        # name of branch on which pipeline need to trigger
    

    But actually what happens, is that it triggers two pipelines. Take an example, let suppose we have two pipelines A and B and we want to trigger B when A finishes. So in this scenario B runs 2 times, once when you do a commit (parallel with A) and second after A finishes.

    To avoid this two times pipeline run problem follow the below solution

    trigger: none # add this trigger value to none 
    resources:
      pipelines:
      - pipeline: RELEASE_PIPELINE # any arbitrary name
        source: PIPELINE_NAME.    # name of the pipeline shown on azure UI portal
        trigger:
        branches:
          include:
            - dummy_branch        # name of branch on which pipeline need to trigger
    

    By adding trigger:none second pipeline will not trigger at start commit and only trigger when first finish its job.

    Hope it will help.