I've set up a GitLab CI configuration intended to trigger pipelines only on the develop and main branches when the commit message starts with "deploy" and the event is a push. Despite this, the pipeline is unexpectedly executing on push events to any branch, including ones not specified in the configuration, such as feature/partially_fill. Here's my current .gitlab-ci.yml setup:
workflow:
rules:
- if: '$CI_COMMIT_BRANCH == "develop" && $CI_COMMIT_MESSAGE =~ /^deploy.*/ && $CI_PIPELINE_SOURCE == "push"'
- if: '$CI_COMMIT_BRANCH == "main" && $CI_COMMIT_MESSAGE =~ /^deploy.*/ && $CI_PIPELINE_SOURCE == "push"'
include:
- local: '/.gitlab-ci-develop.yml'
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
when: always
- local: '/.gitlab-ci-main.yml'
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: always
The intention is clear: pipelines should only run on develop and main branches under specific conditions. However, it's not behaving as expected.
Questions:
Any insights or suggestions to correct this behavior would be greatly appreciated. Thank you in advance for your help!
The problem was with the using the Include function don't know why but it was fixed using the following CI:
stages:
- trigger-services
workflow:
rules:
- if: $CI_COMMIT_BRANCH == "develop" && $CI_COMMIT_MESSAGE =~ /^deploy.*/
- if: $CI_COMMIT_BRANCH == "main" && $CI_COMMIT_MESSAGE =~ /^deploy.*/
develop:
stage: trigger-services
rules:
- if: $CI_COMMIT_BRANCH == "develop"
trigger:
include: '/.gitlab-ci-develop.yml'
strategy: depend
production:
stage: trigger-services
rules:
- if: $CI_COMMIT_BRANCH == "main"
trigger:
include: '/.gitlab-ci-production.yml'
strategy: depend