Skip to content

Instantly share code, notes, and snippets.

@pangyuteng
Last active August 28, 2022 17:55
Show Gist options
  • Save pangyuteng/b124f43c53f8413cd3666b7b52f060d6 to your computer and use it in GitHub Desktop.
Save pangyuteng/b124f43c53f8413cd3666b7b52f060d6 to your computer and use it in GitHub Desktop.
CI_COMMIT_TAG alternative
  script:
    - echo hello cicd
  rules:
    - if: "($CI_PIPELINE_SOURCE == 'pipeline' || $CI_PIPELINE_SOURCE == 'web') && $CI_COMMIT_TAG != null && $CI_COMMIT_BRANCH == 'main' "

since above rule with CI_COMMIT_TAG is only triggered when tag is pushed to gitlab, one can use the below to execute commands only when a commit is tagged via pipeline.

  script:
    - |
      if [[ $(expr length $(git describe --exact-match --tags)) > 0 ]] && [[ $CI_COMMIT_BRANCH = 'main' ]]; then
        echo $CI_COMMIT_SHORT_SHA is tagged as $(git describe --exact-match --tags)
        echo hello cicd  
      else
        echo no tags found for commit $CI_COMMIT_SHORT_SHA
      fi
  rules:
    - if: "($CI_PIPELINE_SOURCE == 'pipeline' || $CI_PIPELINE_SOURCE == 'web')"
@pangyuteng
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment