3

The goal

I'm pretty new to Azure and pipelines, and I'm trying to trigger a pipeline from a pr in Azure. The repo lives in Github.

Here is the pipeline yaml: pipeline.yml

trigger: none # I turned this off for to stop push triggers (but they work fine)

pr:
  branches:
    include:
      - "*" # This does not trigger the pipeline 

stages:
  - stage: EchoTriggerStage
    displayName: Echoing trigger reason
    jobs:
      - job: A
        steps:
          - script: echo 'Build reason::::' $(Build.Reason)
            displayName: The build reason

# ... some more stages here triggered by PullRequests....
# ... some more stages here triggered by push (CI)....

The pr on Github looks like this: enter image description here

The problem

However, the pipeline is not triggered, when the push triggers work just fine.

I have read in the docs but I can't see why this does not work.

The pipeline is working perfectly fine when I am triggering it through git push. However, when I try to trigger it with PR's from Github, nothing happens. In the code above, I tried turning off push triggers, and allow for all pr's to trigger the pipeline. Still nothing.

I do not want to delete the pipeline yet and create a new one.

Update

I updated the yaml file to work as suggested underneath. Since the pipeline actually runs through a push command now, the rest of the details of the yaml file are not relevant and are left out.

Other things I have tried

  • Opening new PR on Github
  • Closing/Reopening PR on Github
  • Making change to existing PR on Github

-> Still no triggering of pipeline.

meerkat
  • 932
  • 2
  • 14
  • 38

3 Answers3

3

You have a mistake in your pipeline. It should be like this:

trigger: none # turned off for push

pr:
  - feature/automated-testing

steps:
- script: echo "PIPELINE IS TRIGGERED FROM PR"

Please change this

  - stage:
      - script: echo "PIPELINE IS TRIGGERED FROM PR"

to

  - stage:
    jobs:
    - job:
      steps:
      - script: echo "PIPELINE IS TRIGGERED FROM PR"

EDIT

I used your pipeline


trigger: none # I turned this off for to stop push triggers (but they work fine)

pr:
  branches:
    include:
      - "*" # This does not trigger the pipeline 

stages:
  - stage: EchoTriggerStage
    displayName: Echoing trigger reason
    jobs:
      - job: A
        steps:
          - script: echo 'Build reason::::' $(Build.Reason)
            displayName: The build reason

# ... some more stages here triggered by PullRequests....
# ... some more stages here triggered by push (CI)....

and all seems to be working.

Here is PR and here build for it

enter image description here

I didn't do that but you can try to enforce this via branch policy. TO do that please go to repo settings and then as follow:

enter image description here

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
3

The solution was to go to Azure Pipelines -> Edit pipeline -> Triggers -> Enable PR validation.

Alex AIT
  • 17,361
  • 3
  • 36
  • 73
meerkat
  • 932
  • 2
  • 14
  • 38
  • `Enable PR validation` does not seem to exist anymore - any ideas? I am using Azure Git repo not GitHub, may be this is why it is missing... – Emil Oct 13 '21 at 18:22
1

You can follow below steps to troubleshooting your pipeline.

1, First you need to make sure a pipeline was created from the yaml file on azure devops Portal. See example in this tutorial.

2, Below part of your yaml file is incorrect. - script task should be under steps section.

Change:

stages:
- stage:
    - script: echo "PIPELINE IS TRIGGERED FROM PR"

To:

 stages:
 - stage:
   jobs:
   - job:
     step:
     - script: echo "PIPELINE IS TRIGGERED FROM PR"

3, I saw you used template in your yaml file. Please make sure the template yaml files are in correct format. For example:

the dockerbuild-dashboard-client.yml template of yours is a step template. You need to make sure its contents is like below:

parameters:
...
steps:
- script: echo "task 1"
- script:  echo "task 2"

And webapprelease-dashboard-dev-client.yml of yours is a job template. Its contents should be like below:

parameters:
  name: ''
  pool: ''
  sign: false

jobs:
- job: ${{ parameters.name }}
  pool: ${{ parameters.pool }}
  steps:
  - script: npm install
  - script: npm test
  - ${{ if eq(parameters.sign, 'true') }}:
    - script: sign

4, After the pipeline was created on azure devops Portal. You can manually run this pipeline to make sure there is no error in the yaml file and the pipeline can be successfully executed.

5, If All above are checked, but the PR trigger still is not working. You can try deleting the pipeline(created on the first step) created on Azure devops portal and recreated a new pipeline from the yaml file.

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • Thanks. The pipeline is running on Azure with `trigger:` now from `git push`, so the syntax should be ok. The PR is still not working however.. – meerkat Dec 02 '20 at 07:45
  • @meerkat I copied your updated yaml. The pr trigger worked perfectly on my side. Could you have a try deleting the pipeline definition from azure pipeline(not the yaml file in github). And recreate a new one. It is very easy to recreate a pipeline definition from an existing azure-pipelines.yml file. – Levi Lu-MSFT Dec 02 '20 at 08:01
  • @meerkat You need to make sure the azure-pipelines.yml file exists in the pr target branch too. – Levi Lu-MSFT Dec 02 '20 at 08:03
  • the `azure-pipelines.yml` file exists in both the target and base branch. By deleting the pipeline defenition, do you mean deleting the whole pipeline in **Pipelines**? And creating the same one from the yaml? – meerkat Dec 02 '20 at 08:37
  • @meerkat Yes, delete the pipeline definition in Pipelines. And create the same one from the yaml. – Levi Lu-MSFT Dec 02 '20 at 09:10