gitlab-ci-local
gitlab-ci-local copied to clipboard
rules:changes
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.
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.
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.