'GitLab CI: skip job if only certain files have changed
I need to skip a GitLab CI job in my pipeline, if the only changes part of my commit/merge request are related to *.md, eslintrc.json or jsconfig.json files.
Examples:
- If these files have changed, but others like *.js have changed too: job should run.
- If these files are not changed at all, but other *.js files have changed: job should run.
- If README.md and eslintrc.json have changed and nothing else has changed: job should not run.
I have tried to accomplish this, but I have not found except:changes nor rules:when:never useful so far. How can I do it?
Solution 1:[1]
There is a similar question with this problem including a suggestion for a workaround in the comments. (Is there a way to skip a pipeline when there are markdown changes only?) The rules:when:never or except:changes feature doesn't seem to support this at the moment. They opened a ticket with GitLab.
Solution 2:[2]
If I get you correctly, you need to have except:changes convention in your CI file.
Take a look at this example. The Job runs in any condition in case the *.md, eslintrc.json, and jsconfig.json have changed. In that case, the pipeline won't run. Check the except-changes stage of the below example.
On the other hand, you can set to run the pipeline in case any js files have changed. Check the * only-changes* stage of the below example.
stages:
- except-changes
- only-changes
ignore-file-changes:
stage: except-changes
script:
- echo "Skip running the pipeline if *.md, eslintrc.json and jsconfig.json has any kind of change."
except:
changes:
- "**/*.md"
- eslintrc.json
- jsconfig.json
- README.md
pass-the-pipeline:
stage: only-changes
script:
- echo "Run only *.js and Dockerfile files has any kind of change."
only:
changes:
- Dockerfile
- "**/*.js"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | svov |
| Solution 2 | Numb95 |
