Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab CI run when commit message matches the regex

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?

like image 256
Muhammad Sawaiz Avatar asked Dec 08 '25 10:12

Muhammad Sawaiz


1 Answers

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
like image 59
Assaf Avatar answered Dec 10 '25 13:12

Assaf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!