2

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

luismauriz1
  • 21
  • 1
  • 2

1 Answers1

3

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.

Jane Ma-MSFT
  • 4,461
  • 1
  • 6
  • 12
  • thanks, the tag trigger are now working fine! For the condition I have another Question: I use your comment condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) to skip this stage in every branch except the master branch. Now my example: My branch is named 1620-to-PipelineTrigger Now I want to include this Branch in one stage. How could I change the condition to fit with my specific Branch name ? – luismauriz1 Apr 24 '21 at 18:18
  • @luismauriz1 Please check my Update 2! : ) – Jane Ma-MSFT Apr 26 '21 at 06:18
  • Hi, yes there are updates! It is now fully working, sorry for my late answer. I have just another small question about Tag Triggering: Is there a Way, to implement a Tag trigger into the condition ? I have now my two conditions for the two branches Where the stage should work. But when I want to run the stage in another Branch, whitch is not one of the two in the condition i want to implement a Comment as a Tag or as a Commit. Is there a possible way, to do this ? Maybe I should create a different stage where the condition is (1/2) – luismauriz1 May 03 '21 at 07:00
  • "If it is not one of my two Branches (master, stable,..) a variable should set to true. This true, i can check later on. The stage where my wish is is our Build script. In master/stable the stage should build always, in my other branches (not those two) There should be an opt in mode. Normally no building, but when I activate it, then build. – luismauriz1 May 03 '21 at 07:00
  • This was my intention: 'condition: or(eq(variables['Build.SourceBranch'], 'refs/remotes/origin/master'), eq(variables['Build.SourceBranch'], 'refs/remotes/origin/stable'), eq(startsWith(variables['build.sourceBranch'], 'refs/tags/BuildAndInstall'))' So I have my two branch conditions and the third trigger is my tag trigger here. My trigger is called in this case 'BuildAndInstall'. Do you know, if that is working ? :) – luismauriz1 May 03 '21 at 12:02