I have a GitLab CI job that I want to only run for tags
or for two special branches (develop
, main
).
only:
- develop
- main
- tags
This job has a dynamic variable that I set using the rules
feature:
variables:
IMAGE_TAG: $CI_COMMIT_TAG # defaults to the pushed commit tag name
rules:
- if: $CI_COMMIT_REF_NAME == 'develop'
variables:
IMAGE_TAG: 'develop'
- if: $CI_COMMIT_REF_NAME == 'main'
variables:
IMAGE_TAG: 'main'
The linter gives me this error though:
jobs:build config key may not be used with
rules
: only
I looked around and it looks like you can't use rules
together with only
.
If I remove the only
directive, then this job will also run on any branch. How do I adjust my script so that I can set the variable dynamically but also limit the job to only run on tags and certain branches?