Using nested variable in “rules:changes”
I’m referring to the keyword “rules:changes”.
In GitLab-ci documentation, there is a basic example demonstrating the usage of variables to create more adaptable rules.
docker build:
variables:
DOCKERFILES_DIR: 'path/to/files'
script: docker build -t my-image:$CI_COMMIT_REF_SLUG .
rules:
- changes:
- $DOCKERFILES_DIR/**/*
I tried to push that a bit further using a nested variable (I need it
because of a ci template that I’m building):
docker build:
variables:
DOCKERFILES_DIR: "docker"
WATCH_FILE: "${DOCKER_DIR}/Dockerfile"
script: docker build -t my-image:$CI_COMMIT_REF_SLUG .
rules:
- changes:
- $WATCH_FILE
But the job is never executed. After some attempts, I came to the conclusion
that nested variables do not work in this context.
Steps to reproduce
This is how I’m testing it:
build-job:
stage: build
variables:
DOCKER_DIR: "docker"
WATCH_FILE: "${DOCKER_DIR}/Dockerfile"
script:
- echo "Compiling the code..."
- echo "Compile complete."
rules:
- changes:
- $WATCH_FILE
build-job_1:
stage: build
variables:
WATCH_FILE: "docker/Dockerfile"
script:
- echo "Compiling the code..."
- echo "Compile complete."
rules:
- changes:
- $WATCH_FILE
I expect to see both jobs executed when I change “docker/Dockerfile”. Yet,
only build-job_1 works.
Versions
- Self-managed (GitLab Enterprise Edition v16.9.3-ee)
- GitLab.com SaaS
- Self-hosted Runners