whatever
whatever

Reputation: 3687

Azure DevOps : how to disable CI trigger on a YAML template pipeline?

In template pipelines you can't place any trigger statement such as trigger: none as specified in Microsoft's docs to disable ci trigger, so I wonder how do you prevent these pipelines from being executed every time you update them or any other yaml file in the same branch?

Upvotes: 61

Views: 80086

Answers (6)

Mifeet
Mifeet

Reputation: 13648

The pipeline yaml definition now supports disabling all triggers with

trigger: none

Reference

Upvotes: 113

Nick.Mc
Nick.Mc

Reputation: 19225

There are no less than three spots in Azure DevOps that may be used to disable automatic build. Which one do you use to disable the irritating automatic builds that occur? Not sure

Firstly, Pipeline triggers as described here. I had to disable this to stop GitHub kicking off an automatic pipeline for PR's https://stackoverflow.com/a/74133429/1690193

Confusingly this isn't in the immediate pipeline hamburger menu, it's under "Edit" then hamburger/triggers. As far as I can tell it doesn't change any source code but it does request a commit message. So much for YAML being the one true definition of deployment

Secondly, In Project/Settings there's a switch for "Disable implied YAML CI trigger".

Thridly, trigger: none in the YAML itself. This being the only actual area where your config is captured in Git

Upvotes: 1

Holy semicolon
Holy semicolon

Reputation: 1389

First you need to go to your Pipelines dashboard, then select the pipeline that you want to disable CI for it Pipelines Dashboard Image

then Click on Edit

Edit Pipeline Image

You will be redirected to the pipeline yaml file, from there you will click on the vertical ellipsis => Triggers

enter image description here

and here you go, you can disable CI for your pipeline that easily

enter image description here

Save it, and you are done.

Upvotes: 17

VivekDev
VivekDev

Reputation: 25543

Other answers are fine.

Here is another approach I found. I have a yaml based build pipeline. I did not want to touch the yaml just for disabling the trigger. So I disabled the pipeline as follows.

  1. Pick your pipeline and double click to edit it.

Pick your pipeline and edit it

  1. Go to the settings.

Go to settings

  1. Now you should see an option to disable. Note here we are disabling the pipeline, not just disabling trigger to the pipeline.

Disable pipeline

Upvotes: 6

whatever
whatever

Reputation: 3687

So in the end in a template pipeline you can't state something like trigger: none (to set only manual triggering) and you cannot specify stages or jobs, only steps are allowed (so you can't define any condition to prevent pipeline execution on the job or on the stage).

You have an option to disable the CI trigger by going in the triggers section for the template pipeline and select the following:

enter image description here

I don't like much this option because it means having pipeline configuration that is not captured in the yaml pipeline definition but I found no other way to disable the template pipeline from being triggered every time something (including the pipeline itself) is updated in its branch.

Upvotes: 43

Krzysztof Madej
Krzysztof Madej

Reputation: 40849

If you want to update your template without affecting pipelines which uses this template make a change on separate branch and merge it to master (or whatever you use) once you are sure that you have what you want.

The same applies if you use template from different repo:

# Repo: Contoso/WindowsProduct
# File: azure-pipelines.yml
resources:
  repositories:
    - repository: templates
      type: github
      name: Contoso/BuildTemplates
      ref: refs/tags/v1.0 # optional ref to pin to

jobs:
- template: common.yml@templates  # Template reference
  parameters:
    vmImage: 'vs2017-win2016'

By default you use template from your main branch, but you can point to any branch you want. Thus you can also test that your changes on limited pipelines as you need to point directly to a branch where you modified your template.

Let's say you have that branching:

master
|_ feature/add-extra-step

And you make a change in template but on feature/add-extra-step by adding additional step.

Now hen you trigger pipeline which uses that template:

  • trigger goes from master - your additional step in template won't be run
  • trigger goes from feature/add-extra-step - your additional step will be run

I made a change in template on feature/extra-step branch:

enter image description here

And this is change is not avialable when I run pipeline (even the same pipeline) on master:

enter image description here

If you for instance don't want to trigger ci build making changes on template, pleace commit those changes with phrase [skip ci] in th git message. Check here for more details.

Upvotes: 2

Related Questions