3

I am trying to only trigger the pipeline when commit message has the conditional phrase. I know this has been asked a lot of times and there are helpful answers available. I have also checked gitlab ci documentation and it also provide the right ways to do it.

Still the stage is built no matter the required phrase is in commit message or not. Here is the .yml code.

before_script: - export LC_ALL=en_US.UTF-8 - export LANG=en_US.UTF-8 - export BUILD_TIME=$(date '+%Y-%m-%d %H:%M:%S') - echo $branch stages: - build build_job: stage: build only: variables: - $branch - $CI_COMMIT_MESSAGE =~ /\[ci build]/ script: - bundle fastlane - fastlane build 

Anyone have any idea that what is wrong with it?

2 Answers 2

4

consider the next solution:

 before_script: - export LC_ALL=en_US.UTF-8 - export LANG=en_US.UTF-8 - export BUILD_TIME=$(date '+%Y-%m-%d %H:%M:%S') stages: - build build_job: stage: build rules: - if: $CI_COMMIT_MESSAGE =~ /\[ci build]/ script: - bundle fastlane - fastlane build 
Sign up to request clarification or add additional context in comments.

2 Comments

Except for the refs part, how does your answer differ from the accepted one?
This looks like a much more explicit solution than the one with "only" and "variables". And it also works.
2

Maybe you can remove the variable $branch and use only: refs here some example

before_script: - export LC_ALL=en_US.UTF-8 - export LANG=en_US.UTF-8 - export BUILD_TIME=$(date '+%Y-%m-%d %H:%M:%S') stages: - build build_job: stage: build script: - bundle fastlane - fastlane build only: variables: - $CI_COMMIT_MESSAGE =~ /\[ci build]/ refs: - /^develop*.*$/ 

you can use regex in refs , in my example meaning : when branch name contain develop and commit message contain [ci build] then run the stages

you can modify thats regex.

thats method used in my production.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.