Home > Software engineering >  How do I prevent pushes done from pipelines from triggering CI jobs in Azure Pipelines?
How do I prevent pushes done from pipelines from triggering CI jobs in Azure Pipelines?

Time:11-10

This question is about Azure Pipelines, but let me start by contrasting it: In GitHub Actions, as long as a workflow uses the provided $GITHUB_TOKEN variable to authenticate and push changes back to the repository in which the workflow is running, this will not trigger more workflows.

This can be very important in some scenarios where part of the workflow functionality is to make changes to the repository in which it runs, and one workflow could otherwise set off a chain reaction of workflows, all triggering each other. Our scenario fits this description, and I assume GitHub built Actions this way for this very reason.

I have been trying to achieve the same thing in Azure Pipelines, but I cannot figure out how, so I would be thankful for any guidance.

Azure Pipelines has the equivalent of the $GITHUB_TOKEN variable — in Azure Pipelines it's called $(System.AccessToken), and you can use this token at the Git level to authenticate against the repository, and interact with the repository subject to any permissions granted to the service account running your pipeline.

But using this provided token does not suppress CI triggers unfortunately.

I have enabled this setting in hopes that it would add this functionality to the job access token:

enter image description here

But unfortunately it has no effect on this aspect; pushing using the $(System.AccessToken) variable still triggers any CI triggers matching the contents of the push.

I know that one can opt out of CI triggers using certain "tags" in commit messages, but this is not a feasible option in our case because the commits are created by external tooling and we do not have full control over the commit message. (And besides those tags in every commit message would pollute the history.)

What am I missing? Is this really not possible to achieve with Azure Pipelines?

CodePudding user response:

You can opt out of CI triggers entirely by specifying trigger: none in your YAML pipeline.

Please refer to :Build Azure Repos Git repositories - Azure Pipelines

For example:

# A pipeline with no CI trigger
trigger: none

CodePudding user response:

If your pipeline is pushing changes to a code repo, it can prevent that push from triggering any further CI pipelines by putting [skip ci] in the commit message.

See https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#skipping-ci-for-individual-pushes

  • Related