Leo Varghese
Leo Varghese

Reputation: 175

How to trigger azure devops build pipeline based on the commit message?

How can I get a build triggered off of a specific commit?


I am building an Azure Devops project. the project has both UI and Backend application codes. Both the codes are placed as a single project in GitLab. But different teams are working for UI and Backend. I need to configure two build pipelines one for UI changes and one for backend changes.

What I need is to trigger a specific pipeline based on the commit messages. ie; if a UI change is made, then the commit message will contain a keyword "UI_CHANGES" in it. The Azure DevOps should recognize this and trigger the UI build pipeline.

Can I make use of Git tags here or other possible ideas?

Upvotes: 3

Views: 8189

Answers (3)

T.Todua
T.Todua

Reputation: 56557

Method 1:

Build when commit message contains a specific word (source):

...
steps:
  - bash: echo "Hello world"
    condition: contains(variables['Build.SourceVersionMessage'], 'HEY_DONTBUILD')

if you want to inverse logic, add not outside, i.e.: not(contains(...))

Method 2:

Another way is to include [ci skip] (or other special phrases in commit message) to skip the build for that commit.

Method 3:

Use only flag for different projects (source):

rspec:
  script: ...
  only:
    variables:
      - $CI_COMMIT_MESSAGE =~ /some-regexp/

Upvotes: 7

Jonas
Jonas

Reputation: 315

In my opinion some kind of "path filter" is what you need. Azure DevOps has an integrated "path filter" but this works only for repos hosted on Azure Devops.

My proposals what you could do in your current situation.

  • Move your repository to Azure DevOps This is the best solution in my eyes but not applicable if you have to stick with GitLab for any reason

    • Pro: You have repo and pipelines at the same location
    • Con: You have to move the repo and set up new memberships etc.
  • Build/Publish with GitLab I am not experienced with pipelines in GitLab so I cannot say if this is a viable solution

    • Pro: You have repo and pipelines at the same location and don't need to move
    • I am not sure how building / publishing works with GitLab (neither pro nor con)
  • Mirror your GitLab repo to Azure DevOps You could use this extension to constantly mirror your repo from GitLab to Azure DevOps and build / publish with the pipeline's integrated path filter

    • Pro: You don't need to move but can use the pipelines of Azure DevOps
    • Con: You are dependent on the extension which only "connects" two independent repos.
  • Connect your GitLab repo with Azure DevOps and do the logical part within the pipeline I think this is the least favorable solution because you have to do all the logical stuff by hand within your pipeline. Nevertheless if you are interested in this solution I recommend a further look at this extension. But it is not as comfortable as the default path filter.

UPDATE I just had a deeper look to this extension and I don't think that this fits your needs. Sorry for that. Nevertheless you can just connect to your GitLab repo without the extension. Just create a PAT for reading your repos and add a Service Connection for "Other git" in Azure DevOps.
As mentioned before you could do the logic of what to build within your pipeline (not favorable).

Upvotes: 0

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41775

You don't need to run the pipeline according to the commit message, you can create two pipelines and in the trigger determine which will run when with the Path filters:

enter image description here

Upvotes: 2

Related Questions