简体   繁体   中英

Azure DevOps pipelines resource trigger not working

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.

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'

在此处输入图像描述

So in your case I would try this:

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

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.

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:

修改设置

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM