Search code examples
azureazure-devopsazure-yaml-pipelines

Azure Pipeline Triggers in Azure Devops: Trigger a pipeline when another completes not working as expected


For my service I have:

  • A yaml build pipeline configured in Azure DevOps
  • A yaml deploy pipeline configured in Azure DevOps

My service repo is hosted in Azure DevOps.

I have configured the branch policies so that when a PR is opened, my build job is triggered. I do not want a build happening before this (e.g. on a commit)

I want my deploy pipeline to be triggered by the build job finishing. I have tried many configurations and I have not been able to achieve this. I have also tried configuring from the Azure DevOps UI so that the deploy pipeline listens for the build job completing - doesn't work.

Any help on achieving this (to my mind, very simple!) workflow would be greatly appreciated.

My build yaml has:

trigger: none

and this is working fine, being triggered by the branch policy.

My deploy yaml has the following, I am expecting this pipelines section to listen for my build job completing. I am guessing the trigger: none is overriding somehow, because the build trigger is configured in the UI. However, I cannot enable a trigger here, because it causes the pipeline to start when a commit is made, and this pipeline depends on the build job completing.

trigger: none

resources:
  repositories:
    - repository: my-template-repo
      type: git
      name: Templates
  pipelines:
    - pipeline: build
      source: my-build-job
      trigger:
        branches:
          include:
            - '*'
        stages:
          - Docker

Configuring triggers both in yaml and the Azure DevOps UI


Solution

  • Pipeline completion triggers use the Default branch for manual and scheduled builds setting to determine which branch's version of a YAML pipeline's branch filters to evaluate when determining whether to run a pipeline as the result of another pipeline completing. By default this setting points to the default branch of the repository. See more detailed info from Branch considerations.

    Please check whether your deploy yaml file is in the default branch of your repo. If not, change your pipeline's Default branch for manual and scheduled builds to the branch where your yaml file is located. For example, if your deploy.yml is in the feature branch, then set the Default branch for manual and scheduled builds to feature.

    To change Default branch for manual and scheduled builds, go to edit your pipeline, More actions -> Trigger -> YAML.

    enter image description here

    enter image description here

    Don't set any triggers in the user interface enter image description here