0
votes

I am using the yaml pipelines in Azure DevOps Pipelines and I see they have two specific trigger keys trigger and pr.

I want it setup so that a few pipelines I have to run tests and security checks only run when a PR on a feature branch or bugfix branch is created (or appended to) but not when they are just pushing to a feature or bugfix branch that does not have a PR yet.

Here is what I have for the pr key:

pr:
  branches:
    include:
      - bugfix/*
      - feature/*
  paths:
    include:
      - Source/Frontend/*

This is for a js frontend pipeline that runs tests, linting, and coverage so I have it limited to only changes to the folder that contains the frontend code.

What do I set the trigger key to in order to accomplish the above stated goal?

I have tried leaving it as default by excluding a trigger key in my yaml file, but that just picks up every commit in any folder. I have also tried trigger: none but that seems to stop it from running at all. And I have also tried have the trigger key be the same as the pr key, but when I make a PR, it is not fired off.

I have ensured that the trigger overrides in Azure DevOps are turned off, so it should be going off of whatever is in the yaml.

3

3 Answers

2
votes

I tested adding trigger: none, which can prevent pipeline from being triggered by CI.

trigger: none 
pr:
  branches:
    include:
    - master

enter image description here

In addition , you can also tell Azure Pipelines to skip running a pipeline that a commit would normally trigger. Just include [skip ci] in the commit message or description of the HEAD commit and Azure Pipelines will skip running CI.

You can use any of the variations below:

  • [skip ci] or [ci skip]
  • skip-checks: true or skip-checks:true
  • [skip azurepipelines] or [azurepipelines skip]
  • [skip azpipelines] or [azpipelines skip]
  • [skip azp] or [azp skip]
  • ***NO_CI***
1
votes

Refer to the documentation on the pr block. It is only for GitHub repos. For Azure DevOps repos, use branch policies to configure PR builds.

You want trigger: none with an accompanying branch policy.

1
votes

Turns out my problem was two-fold.

@Hugh Lin - MSFT helped a bit, but what prevented it from working was the following:

  1. I thought the branches included in the pr key were where the PR was coming from not be merged into, so I changed that from bugfix/* and feature/* to just develop.
  2. The pipeline yaml only existed in a branch off of develop and did not exist in the develop branch.