gitlab-ci-local icon indicating copy to clipboard operation
gitlab-ci-local copied to clipboard

rules:changes

Open ck-trigfb opened this issue 2 years ago • 2 comments

In Gitlab CI you can add the keyword "rules:changes" for a job that should only be executed if specified file changed.: https://docs.gitlab.com/ee/ci/yaml/#ruleschanges

Example:

build:
  script:
    - echo "building"
  rules:
    - if: $CI_COMMIT_BRANCH == 'master'
      changes:
        - src/**/*

What i want to achieve with that: Assuming you multiple services and all of them will be compiled in a big pipeline. So if i only change something in one of the services i have to wait since the whole pipeline finished building. With "rules:changes" i want to achieve something similar other tools like skaffold do: Only build that service / container where changes in code / configuration happend.

Actual problem: gitlab-ci-local seems to completely ignore that setting. I dont get an error but the job runs regardless of whether changes take place or not.

ck-trigfb avatar Feb 23 '22 12:02 ck-trigfb

Its ignored on purpose for now 🤣

One way to solve this is via checksum comparison of what ever is specified in changes: unfortunately we can't rely on git commit sha's via git log command, like remote can.

firecow avatar Feb 23 '22 13:02 firecow

Maybe you can do somthing like this git diff --name-only HEAD HEAD~1 or this: git diff --name-only HEAD~1

This will result in something like this:

.gitlab-ci-local/.gitignore
.gitlab-ci.yml
src/main/java/com/example/demo/DemoApplication.java

Then you can compare if some of the changed files match to the filter criteria in the "rules:changes" section.

ck-trigfb avatar Feb 23 '22 14:02 ck-trigfb