3

how can I start a job with gitlab-ci only when I create a new tag with a specific branch? I try everything but it still doesn't work.

stages: 
  - shov server

test:
  stage: shov server
  rules: 
    - if: '$CI_COMMIT_TAG && $CI_COMMIT_BRANCH == "CI_merge"'
      when: always
  tags: 
    - runner
  script:
    - docker-compose -f docker-compose.yml down 
    - docker-compose -f docker-compose.yml build 
    - docker-compose -f docker-compose.yml up -d 
jake
  • 41
  • 1
  • 3
  • 1
    Does this answer your question? [How to run Gitlab-CI pipelines only branch and tag?](https://stackoverflow.com/questions/72040149/how-to-run-gitlab-ci-pipelines-only-branch-and-tag) – quoc9x Sep 02 '22 at 14:42

1 Answers1

0

AFAIK this is not possible. When the Pipeline runs for a tag, there is no variable defined that indicates the branch. You see this for yourself by looking through all available variables with export. Gitlab Documentation

You could perhaps try to find the branch, which the commit is on. Something like git branch -a --contains $CI_COMMIT_SHA or something similar. However you probably can't do that in the rules, and have to do it in the script, or in the before_script with custom logic to stop the rest of the script from running.

Hope this helps.

Jeanot Zubler
  • 979
  • 2
  • 18