How does CI_COMMIT_TAG get populated when multiple tags on a commit?

I am looking to figure out how CI_COMMIT_TAG is populated. I have a repository scheme where I will need to have multiple tags on a single commit. On top of that, I want to only trigger the pipeline for a specific RegExp for the CI/CD pipeline.

The following is my workflow rules…

workflow:
  rules:
    # Only run the workflow if it matches a valid branch/tag pattern
    # Tag: 1.2.3
    - if: $CI_COMMIT_TAG =~ /^\d+\.\d+\.\d+$/
      when: always
    - if: $CI_COMMIT_BRANCH =~ '/^develop|master$/'
      when: always
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
      when: always
    - when: never

I want to be able to tag a single commit with multiple tags. Example: Tag1 - 1.0.2 Tag2 - zealous.mustard.

When I do this today, I get two pipeline runs, once for tagging with 1.0.2 and once for tagging with zealous.mustard. The zealous.mustard tag is added second. How can I prevent a pipeline from running when the second tag is added of zealous.mustard?

Thanks.

I have a similar problem: I use different tags for versioning of the different flavours of the app I build from the same source code. I would like to run a single test job in the test stage and run one job per tag at the build stage. Have you found a way around this problem?

I think your problem would be possible, but for OP I don’t know or pretty sure it doesn’t work.

The difference between your two is, that you wanna create the tags inside the ci/cd-pipeline and op want them to create beforehand.
And I’m pretty sure git doesn’t allow two tags on one commit. At the end it has two entries (iirc) and so you would get at least two pipeline. and another problem would be that $CI_COMMIT_TAG will most likely not have two strings.

@leandro.peralta I would recommend your two files.

  • gitlab-ci.yml
  • tagging.yml

tagging.yml:

spec:
  inputs:
    tag_name:
    default: "latest"
    type: string
    description: "Define tag name"
---

create-tag:
  script:
     # i think you need this
     # - git config --global user.email "your-email@example.com"
     # - git config --global user.name "Your Name"

     - git tag -a $[[ inputs.tag_name]]
     - git push origin $[[ inputs.tag_name]]

gitlab-ci.yml:

# if you want to trigger via jobs
create-tag-1:
  trigger:
      include: path/to/tagging.yml
      inputs:
         tag_name: "0.9.9"

create-tag-2:
  trigger:
      include: path/to/tagging.yml
      inputs:
         tag_name: "1.0.0"

# or you could use include globally
include: 
    - local: path/to/tagging.yml
      inputs:
          tag_name: "1.0.1"

Beware, I didn’t test it. But I’m kinda confident that such a setup should work.
You might need to add image and tag.

Thanks @botkero. We actually want to create tags remotely that, when pushed, trigger the pipeline. As you say, I don’t think GitLab CI expects more than one tag per commit. Threfore, I believe the simplest solution in our case will be to create a single tag that combines the necessary details for each app flavour. I would then be able to have a rule that checks if the tag contains a specific pattern that matches a flavour.

1 Like