Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 425
meerkat Avatar asked Nov 01 '25 18:11

meerkat


2 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

like image 112
Krzysztof Madej Avatar answered Nov 03 '25 10:11

Krzysztof Madej


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

like image 27
meerkat Avatar answered Nov 03 '25 09:11

meerkat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!