简体   繁体   中英

Using commit triggers to trigger Azure Devops Pipeline in the YAML File

I have a Question about the Pipline trigger in Devops. My team and I are using Azure Devops to develop a software. We use a Branch Specific trigger, to start the pipeline only in out Master Branch. The other branches are ignored in the YAML File.

First part of my question is, that we don't know a way how to trigger the Pipeline over a commit message in our Git tool. For example: "We work in a different branch than the Master branch -->No Pipeline is running. But we want to trigger the pipeline in this Branch for a Specific test just one time. Our way would be to insert a specific command in the commit text to trigger the pipeline."

My second question is, if it's possible to run different stages in different Branches in one YAML file. Here again an example: " In our different Branch, we just want to run our unit tests every push. In our Master Branch we want to run our unit tests and after that, we want to build our application.

So far, we started the pipeline at every push and build a new image everytime. But we dont want that, because some pushs arent working and we just push it. We want to decide when the pipeline is running and whitch stage is running.

I hope you can understand my problem. For further questions, please comment here. Thanks

Question 1:

You can consider using tag triggers to do this. Here is an example:

trigger:
  branches:
    include:
    - master
  tags:
    include:
    - test.*

Then the pipeline will be triggered when working on the master branch or the commit tag is test.* .

Question 2:

You can use conditions. Here is an example:

condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))

Add the condition to your stage, and then the stage will be only triggered by the master branch.

Question 3:

So far, we started the pipeline at every push and build a new image everytime. But we dont want that, because some pushes aren't working and we just push it.

You can skip CI for individual commits .

Just include [skip ci] in the commit message or description of the HEAD commit and Azure Pipelines will skip running CI.

Update 1:

For Question 1, the test.* means a tag which started with test. , such as test.1 , test.0.1 , and so on. You can change the test.* to anything you want.

As for the question your encountered, you can't create a tag called test.* directly because a tag name cannot contain * .

To avoid confusion, you need to create a tag for the commit to trigger the tag CI, rather than writing it directly in the commit text.

The idea

insert a specific command in the commit text to trigger the pipeline.

I don't think is currently supported and tag trigger is an alternative.

Click this document for detailed information about git tag.

Update 2:

Trigger the stage by master branch or 1620-to-PipelineTrigger branch:

condition: or(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(variables['Build.SourceBranch'], 'refs/heads/1620-to-PipelineTrigger'))

You can set only one condition per stage, but you can create more complex conditions using and , or and () .

Click this document to get more detailed information and examples about conditions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM