There are a few ways to run jobs only when there are changes in a specific directory (only, rules, custom logic in a script block). However, I would like to combine this concept with a list of directories inside a parallel matrix, i.e,
image: alpine
stages:
- run
my-job:
stage: run
rules:
- changes:
- $DIR
script:
- echo "In $DIR"
parallel:
matrix:
- DIR: path/to/A/*
- DIR: path/to/B
The intention being that my-job is only added to the pipeline and run for path/to/A when it contains changes, and for path/to/B when it contain changes. Trying this solution, the jobs are never added to the CI -- presumably because the rules are processed before the parallel matrix is.
I do not want to add logic to the script block; I want the job to be excluded from the pipeline altogether unless changes in $DIR exist.
How can I achieve my desired behavior?