Skip to content

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.yaml file
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 branches job should be instantiated.
    • Actual: The only on tags job is instantiated.
  • See the output of the job execution. The $CI_COMMIT_TAG variable is not present (as expected). $CI_COMMIT_TAG == "" got evaluated to true.

Example Project

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.

image

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.

Edited by Braiam