Read CICD predefined job variable names

runner
ci

#1

Hi Guys,

I am really new to Git & GitLab. My aim is to create few CICD jobs which should run when a commit happens on a particular branch. I was going through few topics & videos for the last 2 weeks and come up with yaml file which actually runs now and build some files. My current requirement is to get few parameters like the commited branch name, commited files and then download these files to a remote system. I have gone through the CICD variables and tried to echo these variables to see the values.
echo $CI_COMMIT_REF_NAME simply echoes the same value in the CICD job console.

How can we get this value? Any pointers is highly appreciated.

Thanks in advance!


#2

This should be the full reference guide: https://docs.gitlab.com/ee/ci/variables/README.html#predefined-variables-environment-variables .
Otherwise you might be able to set something up with https://docs.gitlab.com/ee/ci/yaml/README.html#variables
Or do you mean it echos literally: ‘$CI_COMMIT_REF_NAME’ ?


#4

it should be passed to the runner, and usable in a script section:

script:
- echo $CI_COMMIT_REF_NAME
- cp mytestfile.txt $CI_COMMIT_REF_NAME


#5

I got my issue…it was a syntax issue and needs to change according to the runner.
I fix that issue but getting a null value when i read CI_COMMIT_REF_NAME variable.

Below is sample output

Running with gitlab-runner 11.6.0 (f100a208)
on iib-dedictaed-server-description 28fnufWA
Using Shell executor…
Running on DESKTOP-9VN35R5…
Fetching changes…
HEAD is now at 6eefa47 Update .gitlab-ci.yml
From https://gitlab.com/Chandran88/iib-project
6eefa47…e1d018c dev -> origin/dev
Checking out e1d018c1 as dev…
Skipping Git submodules setup
$ echo vAR1:%$CI_COMMIT_REF_NAME%
vAR1:
$ call C:\Users\abhi\IBM\IIBT10\GitRepo\cicd.bat

$CI_BUILD_REF_NAME

Press any key to continue . . .
Job succeeded


#6

ah, was assuming bash syntax, not that experienced with windows shell commands/variables. Sorry, I’m afraid I’m not the person that can help you here.