In job rules you cannot do:
test_prod:
stage: deploy
environment:
name: $ENVIRONMENT
script:
- echo $ENVIRONMENT
- echo $CI_COMMIT_TAG
rules:
- if: $CI_COMMIT_BRANCH == "main" && $CI_COMMIT_TAG
According to this post: $CI_COMMIT_TAG in "if" statemets of regular job
"For example, if you simply push a new commit to the remote, the value of CI_PIPELINE_SOURCE will be push. For push pipelines, many of the Predefined Variables will not exist, such as CI_COMMIT_TAG, CI_MERGE_REQUEST_SOURCE_BRANCH_NAME, CI_EXTERNAL_PULL_REQUEST_SOURCE_BRANCH_NAME, etc.
However if you create a Git Tag either in the GitLab UI or from a git push --tags command, it will create a Tag pipeline, and variables like CI_COMMIT_TAG will exist, but CI_COMMIT_BRANCH will not."
What is the reason for that?