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

How to use 'only' keyword to select which job to run when tag name ends with some specific keyword

Although this seems to be very easy but seems like I am doing something silly somewhere. I am trying to automate my project where I have decided to run either of the jobs where one is for staging and one is for production. I want my deploy-on-staging job to run when my tag released ends with -stage and deploy-on-prod job to run when my tag release ends with -prod. For this I have used only keyword (instead of rules keyword as it was becoming pain for me). But only keyword is not supposed to be working as expected, for me.

The issue I am getting is even after using the only keyword, both of my jobs are still running. Any pointer would be very helpful.

I am just pasting the code of my gitlab-ci.yml which would be useful to you to resolve this issue. Please ping me if you want something else also from the gitlab-ci.yml file.

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

Here is my gitlab-ci section:

variables:
  TagName: ${CI_COMMIT_TAG}

deploy-on-staging:
  stage: deploy
  # rules:
  #   - if: '$TagName == "*-stage"'
  #   - if: '$TagName == "*-prod"'
  #     when: manual
  image: ubuntu:20.04
  # tags:
  #   - docker-executor
  before_script:
    - apt-get update
  script:
    - echo "It's here in stage"
    - echo "$TagName =~ '/^*-stage/'"
  only:
    - tags
    - "$TagName =~ '/^*-stage/'"


deploy-on-prod:
  stage: deploy
  image: ubuntu:20.04
  # tags:
  #   - docker-executor
  # rules:
  #   - if: '$TagName == "*-prod"'
  # before_script:
  #   - apt-get update
  script:
    - echo "It's here in prod"
  only:
    - tags
    - $TagName =~ '/^*-prod/'

>Solution :

Only/except are deprecated https://docs.gitlab.com/ee/ci/yaml/#only–except

to achieve that you want with rules, just use this example

  rules:
    - if: $CI_COMMIT_TAG =~ /-stage/i
      when: always
    - if: $CI_COMMIT_TAG =~ /-prod/i
      when: never
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