Backend: gitlab-ci "rules" should support extended globbing or some negation of changes/exists
Problem to solve
I would like to run a GitLab CI job only if at least one file was changed and changed files were not all html files.
The below syntax will exclude the job from the pipeline when md
files are changed.
job1:
rules:
- changes:
- "**/*.md"
- "*.md"
when: never
- when: always
Intended users
Further details
Assuming a repository made of many types of files. Assume you want to run a compile job only if the commit does not contain only documentation changes (such as *html files only).
The CI keyword allows pattern matching, but does not allow any sort of negation pattern matching.
For that reason, the only way to run the job if any file was changed but not only html files were changed is to list in the "rules: changes:" the entirety of all file extensions, and all files with no extensions.
If changes/exists supported extended globbing, or some sort of negation, this unwieldy workaround would not be necessary.
Additionally in another example, if we change some .py
, .js
and .md
files, then the job should be included in the pipeline.
But if only the .md
file was changed, the job should be excluded.
Proposal
Support extended globbing, akin what bash can do:
rules:
changes:
- "**/!(*.html)"
will run the job if:
- foobar.txt was changed,
- foobar.txt + foobar.html were changed,
but will not run the job if
- foobar.html was changed
The following would be equivalent to bash extended globbing:
mkdir code doc
touch code/foobar.cpp doc/index.html
shopt -u globstar
shopt -s extstar
ls **/!(*.html)