How to use conditions in .gitlab-ci.yml variables?
It is possible:
Add your logic into the variable
section:
variables:
VERSION_LOGIC: '(if [ "$${CI_COMMIT_TAG}" == "" ]; then echo "1.3.5.$$CI_PIPELINE_IID"; else echo "$${CI_COMMIT_TAG}"; fi);'
Now you are able to use this logic in a script secion of a job:
version:
stage: versioning
script:
- VERSION=$(eval $VERSION_LOGIC)
- echo "The current version is set to ${VERSION}."
This is expected behavior.
CI_COMMIT_TAG
is only set to a value in a GitLab job. From https://docs.gitlab.com/ee/ci/variables/README.html
CI_COMMIT_TAG - The commit tag name. Present only when building tags.
Therefore in the variables
section CI_COMMIT_TAG
is not defined, hence equals to "".
So if you want to use CI_COMMIT_TAG
use in job where tags are defined. See https://docs.gitlab.com/ee/ci/yaml/README.html#tags