Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tagging in gitlab CI running multiple times

I created GitLab job to create git tag and push to the repository as following:

  add tag:
  extends: .install_dependencies
  stage: deploy
  image:
    name: nexus-docker.ship.gov.sg/python:latest
    entrypoint: ["/bin/bash"]
  script:
    - echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
    - git tag -a v"$VERSION" -m version"$VERSION"
    - git push origin v"$VERSION"
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_COMMIT_BRANCH

But every-time I pushed from my commit branch, the pipeline is triggered by 2 times: from branch and then tag.
Since the tag is already created in first pipeline, then the second triggered by tag is failed. I only want to make run one time for this job based on the rules.

pipeline triggered 2 times for same commit

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In the Gitlab CI yaml there is a keyword except: to tell the CI when not to run. What you’ll want to do is add this to the task so it only runs once to tag, and then ignores the tag when that comes. This is what your pipeline script might look like:

  add tag:
  extends: .install_dependencies
  stage: deploy
  ...
  except:
    - tags

  script:
    - echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
  ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading