Avoid Pipeline run, if $CI_COMMIT_TITLE / $CI_COMMIT_MESSAGE contains foo


I want:

  • Start the pipeline if the commit branch is master
  • EXCEPT if the commit message / title contains a <regex>

    - apt update
    - if: '$CI_COMMIT_BRANCH == "master"'
      when: always
    - if: $CI_COMMIT_TAG !~ /^Weekly_Release_.*/ || $CI_COMMIT_TITLE =~ /^Finish.+Weekly_Release.*/
      when: never

or do I understand the when: always wrong ?

The problem is … if the developer creating a release, than it will be pushed to master branch which contains as git message “Finish Weekly_Release_20_2022”. That will trigger the first pipeline, and then they push (afterwards) a Git tag “Weekly_Release_2022” on the master branch and this triggers the 2nd pipeline, which I don’t want.

So I want to avoid a run, if push to master and $CI_COMMIT_TITLE OR $CI_COMMIT_MESSAGE contains the words above …

What I’m doing wrong ?

cu denny

First things first. If you want to avoid your pipeline to run unless the conditions are met, you should use “workflow:rules:if”
In second place, remember: gitlab evaluates the rules until the first condition match, in your case, if the branch equals to “main”, the pipeline will execute.
One way to avoid that can be something like:
‘$CI_COMMIT_BRANCH == “main” && ($CI_COMMIT_TAG !~ xxxxxxxx || $CI_COMMIT_TITLE =~ xxxxxx)’

Hope this helps!


1 Like

hi @marcosp

thank you very much. I was wrong … about the if rules … or using it wrong. …

I will try it out the next days… I had to shutdown my other runner nodes … because of this problem and clashing my debian/changelog , because of this :slight_smile:

thank you !

1 Like