15

I have an Azure DevOps pipeline (Pipeline1) that should be triggered when another (Pipeline2) completes. To that end I have implemented a pipelines resource as described in the documentation -

However, it's simply not working. In reality Pipeline2 will be triggered when a new PR is created or manually. I've tested creating a new PR, updating a PR several times, and several manual runs, but no matter what I do Pipeline1 will not trigger.

I've tried two of the examples as defined in the YAML schema reference, and reading further into the Trigger one pipeline after another document, I've tried to prefix the all branches wildcard with refs/heads/.

What must I do to get this working?

What I've tried

Without any branchs explicitly defined -
resources:
  pipelines:
    - pipeline: pipeline2
      source: Pipeline2
      trigger: true
With all branches explicitly defined -
resources:
  pipelines:
    - pipeline: pipeline2
      source: Pipeline2
      trigger:
        branches:
          - "*"
Prefixed the all branches wildcard with refs/heads/ -
resources:
  pipelines:
    - pipeline: pipeline2
      source: Pipeline2
      trigger:
        branches:
          - refs/heads/*

Update

It seems that sadly the pipelines resource does not work on PR's. Why That's the case, I couldn't tell you.

After some further investigation I stumbled across the Incoming Webhook Service Connection in a sprint update. This update is from six months ago and at the time of writing nothing has been added to the YAML schema reference.

However, it turns out that this feature just doesn't work full stop, and even if it did it looks like it will only trigger the default branch of a pipeline, which is no good for us (and probably no good for most use cases).

I did eventually find some documentation on GitHub from a year ago, but unfortunately this only seems to confirm that the Incoming Webhook Service Connection is of no use to us in this case.

5
  • Hi @DavidGard, how about set the 'Build completion' trigger via the classic editor? Does it work? Commented Jan 22, 2021 at 7:28
  • No idea, not something I'm going to try I'm afraid. We've run in to issues when mixing classic and YAML in the past, so I don't want to risk it on this occasion.
    – David Gard
    Commented Jan 22, 2021 at 15:34
  • Okay, @DavidGard. If you want to configure the pipeline definition just in the YAML file, you should make sure have disabled or removed the settings you set via the classic editor. Commented Jan 25, 2021 at 6:45
  • 1
    @DavidGard Did by any chance have this tested across two repositories. I do have the exact same problem and cannot seem to get it to work. All default branches set correctly in both repos as far as I can tell. Also I do get trigger configuration error on the pipeline to be triggered but no further info whatsoever.
    – FloWil
    Commented Dec 22, 2021 at 13:28
  • Are you concluding that pipeline triggers don't work on pr's or did you find some official evidence of that?
    – mwilson
    Commented Jul 8, 2023 at 2:18

3 Answers 3

32

This answer solved it for me.

I had a main and dev branch, and the target pipeline yaml file was not yet pushed up to main. The "Default branch for manual and scheduled builds" in the target pipeline must contain the source file in order for the pipeline to be triggered automatically. (The version of the pipeline that will actually be triggered will be the branch that triggered the original pipeline, as long as they are in the same project.) I changed the value to dev and that solved it.

You can change this setting by going to Edit/Triggers/Yaml/Get sources:

Change setting

3
  • Here is the MS official documentation on what Rachel P is talking about learn.microsoft.com/en-us/azure/devops/pipelines/process/…
    – Bruc3
    Commented Jul 15, 2022 at 13:55
  • For me, it didn't work with the default value it had... at first. I switched it to a topic branch, then my pipelines started working correctly again. Then I switched back to the original value... and it kept on working. ¿?¿?¿?¿?¿?¿? Commented Jul 31, 2023 at 12:36
  • 1
    Instead of switching the default branch from master/main. I pushed the 2nd pipeline to master. Then the triggers in my other environment branches started to work. Commented Feb 16 at 1:58
0

For me works this

resources:        
  pipelines:
  - pipeline: build_pipeline  
    source: kmadof.devops-manual (14)
    branch: master
    trigger:
     branches:
     - '*'

steps:
- bash: env | sort
- task: Bash@3
  inputs:
    targetType: 'inline'
    script: |
      echo 'Hello world'

enter image description here

So in your case I would try this:

resources:
  pipelines:
    - pipeline: pipeline2
      source: Pipeline2
      branch: master
      trigger:
        branches:
          - '*'
0

The Pipeline2 is triggered by PR, so the source branch (Build.SourceBranch) that triggers the pipeline run is the PR merge branch (refs/pull/{PR_ID}/merge).

I also have tested with the 3 ways you posted above, and only the first way can work as expected.

According to my further investigation, it seems that the branch filters on the pipeline resource trigger are only available to the repository branches that you can see on the 'Repos/Branches' page. These branches have the same prefix 'refs/heads/'. The PR merge branch (refs/pull/{PR_ID}/merge) seems is not included.

In your case, the first way should can work. You need to check with the following things:

  1. Make sure you have specified the correct pipeline name of Pipeline2 to the 'source' key.
  2. Check whether Pipeline1 and Pipeline2 are in the same project. If not, make sure you have used the 'project' key to specify the correct project where Pipeline2 is in, and make sure the projects are in the same organization.
2
  • Thanks for the reply. I am using the correct source and the pipelines are in the same project. If this won't work with PR's then unfortunately it's an entirely pointless endeavour. Hopefully this is something that MS will fix quickly.
    – David Gard
    Commented Jan 18, 2021 at 9:16
  • Hi @DavidGard, Ideally, both the first way and the second way should work for PR, but currently only the first way works according to my test. In your case, none of them can work. You also can try to check if you have set 'Build completion' trigger on the classic editor for your 'Pipeline1' (Edit > > triggers). the triggers set on the classic editor will override the triggers set in the YAML file. If you do not set trigger on the classic editor, you can try use the classic editor to see if the 'Build completion' trigger can work. Commented Jan 19, 2021 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.