skip to Main Content

I am trying to write a pipeline to build an image and deploy to the test environment which is hosted on Azure. My codebase lies on GitHub. While trying to trigger the pipeline on a pull request from the source branch against the target branch, I am facing an issue where the pipeline doesn’t trigger for the PR but runs fine for my other conditions, such as, push to develop or master.

The condition used for the PR trigger is as follows:

and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'), startsWith(variables['System.PullRequest.SourceBranch'], 'release/'), eq(variables['System.PullRequest.TargetBranch'], 'master'))

The triggers in the yaml file can be seen below:

trigger:
  branches:
    include:
      - develop
      - master
  paths:
    exclude:
      - k8s/*
      - src/VERSION
      - src/package.json

pr:
  - master

Am I missing something here?

2

Answers


  1. I’m not sure if this will fix it but according to the documentation the System.PullRequest.TargetBranch variable has format refs/heads/main which would mean your condition needs updating to add refs/heads in front of the variables.

    As such I would add a step to echo these variables just to confirm if they have the refs/head prefix and if so adjust your logic accordingly

    Login or Signup to reply.
  2. There are two scenarios:


    Scenario 1: The pipeline was triggered when the pull request is created, but the stages/jobs/tasks with the condition you showed don’t run.

    Then the issue should be related to condition, not trigger.

    I have tested and confirmed that your condition is right. So, it’s probably not the condition notation but something else that’s causing your task not to run.

    Here is a troubleshooting advice:

    Go to the build log, click on the stages/jobs/tasks that were skipped. You will find a comparison between the condition and the real value. From here, you can tell which part of the condition is keeping your tasks from running.


    Scenario 2: The pipeline wasn’t triggered when the pull request is created.

    Then the issue should be related to trigger, not condition.

    Please select documents below for detailed troubleshooting advice based on your case:

    1. I just created a new YAML pipeline with CI/PR triggers, but the pipeline is not being triggered.

    2. My CI or PR triggers have been working fine. But, they stopped working now.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search