2

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?

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Leo Varghese
  • 165
  • 1
  • 2
  • 12
  • Not get your response for several days, would you please share your latest information about this issue? If you have any concern, feel free to share it here – Hugh Lin Jan 09 '20 at 10:02

3 Answers3

3

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/
T.Todua
  • 53,146
  • 19
  • 236
  • 237
2

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

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • 1
    This is not a solution. The path filter is only available for git repos which are directly in Azure DevOps. His repo is on GitLab. – Jonas Jan 06 '20 at 08:59
  • 1
    You are right Jonas . Also, @Shayki your solution can be applied if the code is built on different branches. In my case both the UI and backend developers will be working on the same branch. So branch wise triggering cannot be applied. – Leo Varghese Jan 06 '20 at 09:21
  • @LeoVarghese the path filters are also for the same branch. – Shayki Abramczyk Jan 06 '20 at 10:05
  • I have a question, what if the change is in one of the referenced projects not in the project which is mentioned into the Path specification? Will it work the same as you are talking about? – Umair Tahir Nov 12 '21 at 15:59
0

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).

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Jonas
  • 305
  • 2
  • 16
  • 1
    Many Thanks @Jonas .The first 3 options will not work in my case. I was also thinking of the fourth solution you mentioned. But need to know if any other hidden solutions are available before I make my hands dirty with the logical stuff :). – Leo Varghese Jan 06 '20 at 09:58
  • Ok this is unlucky.. the fourth option is really "dirty". May I ask what the problem with mirroring the repo is? Personally, I would choose the mirroring.. – Jonas Jan 06 '20 at 10:05
  • Mirroring is not a good solution, in my opinion, I think you need to create two pipelines and in the first task check the commit message and cancel/continue the pipeline. – Shayki Abramczyk Jan 06 '20 at 10:11
  • I understand that you are not a fan of mirroring (no one should be) but in your case I think it is a very clean solution. I mean you could just lock the repository for everyone else to write in and it just sticks with your GitLab repo. If you want to do it by hand you can start like you proposed it. – Jonas Jan 06 '20 at 10:20
  • Jonas, We cannot mirror the repo as it is not allowed. @ShaykiAbramczyk Creating two pipelines would work, but before that I need to know if Azure DevOps itself support this functionality. Also, what aboout using Gitlab Tags ? is that only usefull while using gitlab runners ? Can it help me in azure devops ? I am totally blind on Gitlab tags. – Leo Varghese Jan 06 '20 at 10:22
  • I think you are not the only one with this problem ... https://github.com/onlyutkarsh/gitlab-integration/issues/4 + https://github.com/onlyutkarsh/gitlab-integration/issues/5 – Jonas Jan 06 '20 at 11:30
  • I don't know why but that thing keeps my interest ... A bit of research shows there is also a feature request about GitLab integration at Microsoft's Developer Community. Maybe you could back this request with an upvote... – Jonas Jan 06 '20 at 13:49