Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress gitlab CI stage if push only changes README.md

I have a CI build stage that runs whenever someone pushes to the repo, and it takes a long time to run. So I want to configure a .gitlab-ci.yml rule that says if the user is only updating the documentation in README.md, it doesn't need to execute the build stage.

Following the tips in How to exclude gitlab-ci.yml changes from triggering a job, it seems like the way to do this would be to add something like:

stages:
 - A

Stage A:
  stage: A
  rules:
    - changes:
      - "README.md"
      when: never

However, based on the documentation in https://docs.gitlab.com/ee/ci/yaml/#ruleschanges, I think this will also suppress the stage if the push contains multiple files, if one of them is README.md.

In that situation, I want the stage to run, not be suppressed. Is there a way to handle this distinction?

like image 348
LWixson Avatar asked Oct 26 '25 11:10

LWixson


1 Answers

I use this syntax to not trigger pipelines when modifying *.md files

workflow:
  rules:
    - if: '$CI_COMMIT_BRANCH && $CI_COMMIT_BEFORE_SHA !~ /0{40}/'
      changes:
        - "{*[^.]md*,*.[^m]*,*.m,*.m[^d]*,*.md?*,*[^d]}"
    - if: '$CI_PIPELINE_SOURCE == "web"'
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
    - if: '$CI_PIPELINE_SOURCE == "pipeline"'
    - if: '$CI_COMMIT_TAG'
like image 54
Bigouden Avatar answered Oct 28 '25 04:10

Bigouden