Get commit hash

I am currently working on a deployment script that will run as part of my GitLab CI setup. I want to copy a file from one place to another and rename it.

Now I want to find with what commit this file is generated, so I would like to add a commit hash to it.

For this, I would like to use something like this:

cp myLogFile.log /var/log/gitlab-runs/$COMMITHASH.log

The output should be a file with a name for example.

/var/log/gitlab-runs/9b43adf.log

How can this be achieved with GitLab CI?

+6
source share
3 answers

The variable you are looking for CI_BUILD_REFis one of the predefined variables.

All predefined variables are listed here .

+14

git, CI_COMMIT_SHA :

${CI_COMMIT_SHA:0:8}
+18

Starting with GitLab v11.7, you can use $CI_COMMIT_SHORT_SHAwhich returns the first eight characters CI_COMMIT_SHA.

+2
source

Source: https://habr.com/ru/post/1626366/


All Articles