GIT depending on env variable get either release tag id or hash commit id

Viewed 31

I am setting up a GitLab-ci.yml file and want to add a condition where if the env variable is prod get the release tag id, else get the hash commit id.

Can you please suggest how I can achieve it ?

These are the commands which ill be using to get the commit id or tag id :

git log -1 --format=%h
git describe --tags --abbrev=0
1 Answers

Commit sha is provided by Gitlab out of the box. You can use bash scripts to achive what you want

before_script:
- if [[ $ENV == "prod" ]]; then export RELEASE_TAG=$(git describe --tags --abbrev=0); else export RELEASE_TAG="$CI_COMMIT_SHA"; fi;
script:
- echo $RELEASE_TAG
Related