pr not triggered when opening github PR (Azure pipeline YAML)

Viewed 1326

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.

3 Answers

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

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

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.

Related