rules:if can't be used with $CI_COMMIT_TAG to run jobs only on tags
Summary
Can't use rules:if $CI_COMMIT_TAG == "" to run jobs only on commits (not tags).
The use of $CI_COMMIT_TAG to identify pipelines triggered by a tag is suggested here: gitlab#27863 (closed)
I'm also using rules:if to evaluate a custom variable, and rules:changes. That leaves only:tags out of the game.
Steps to reproduce
- Create a new repository with the following
.gitlab-ci.yamlfile
image: alpine:latest
only on branches:
rules:
- if: '$CI_COMMIT_TAG == ""'
script:
- echo only on branches
- env
only on tags:
rules:
- if: '$CI_COMMIT_TAG != ""'
script:
- echo only on tags
- env
- Commit and push. Do not push a tag.
- Look at the pipelines.
-
Expected: The
only on branchesjob should be instantiated. -
Actual: The
only on tagsjob is instantiated.
-
Expected: The
- See the output of the job execution. The
$CI_COMMIT_TAGvariable is not present (as expected).$CI_COMMIT_TAG == ""got evaluated totrue.
Example Project
- Project: https://gitlab.com/briandev/gl-runner-rules-if-ci-commit-tag-bug
-
.gitlab-ci.ymlfile: https://gitlab.com/briandev/gl-runner-rules-if-ci-commit-tag-bug/blob/master/.gitlab-ci.yml -
Pipelines: Notice how it runs the
only on tagsjob regardless of the existence or not of$CI_COMMIT_TAG. https://gitlab.com/briandev/gl-runner-rules-if-ci-commit-tag-bug/pipelines
What is the current bug behavior?
a) rules:if $CI_COMMIT_TAG != "" instantiates the job regardless of the existence or not of $CI_COMMIT_TAG
b) rules:if $CI_COMMIT_TAG == "" does not instantiate jobs triggered by git commits (not tags).
What is the expected correct behavior?
a) rules:if $CI_COMMIT_TAG != "" should instantiate jobs triggered by git tags only.
b) rules:if $CI_COMMIT_TAG == "" should instantiate jobs triggered by git commits only (not tags).
The use of $CI_COMMIT_TAG to identify pipelines triggered by a tag is suggested here: #60085 (moved)
Relevant logs and/or screenshots
only on tags runs when expecting only on branches to be run.
Output of checks
This bug happens on GitLab.com
(If you are reporting a bug on GitLab.com, write: This bug happens on GitLab.com)
Results of GitLab environment info
I don't have access to the gitlab box. I can reproduce on Gitlab v12.3.5-ee with Gitlab Runner v12.4.0.
Results of GitLab application Check
I don't have access to the gitlab box. I can reproduce on Gitlab v12.3.5-ee with Gitlab Runner v12.4.0.
Possible fixes
None yet.
