I have a dummy build script in the Gitlab CI
:
pwd
ci_app_path=$(pwd)
echo "INFO: current directory: $ci_app_path"
and I get this output when the system start the build process:
pwd
/home/kai/gitlab-runners/gitlab-ci-runner/tmp/builds/project-1
ci_app_path=$(pwd)
echo "INFO: current directory: $ci_app_path"
INFO: current directory:
so the variable was not set (or was set only for that line: as I know each line executed separately)
I heard about push/pop mechanism to reach the functionality I desired, but could not find any details, how to implement that.
as I thought, each line is going executed separately. So the variable scope is only one line, where it is defined:
script:
pwd
ci_app_path=$(pwd) && echo "INFO: current directory: $ci_app_path"
output:
pwd
/home/devuser/gitlab-runners/gitlab-ci-runner/tmp/builds/project-1
ci_app_path=$(pwd) && echo "INFO: current directory: $ci_app_path"
INFO: current directory: /home/kai/gitlab-runners/gitlab-ci-runner/tmp/builds/project-1
I don't think that writing the whole script as a one-liner is a good idea/practice.
How to get the variables set while executing the build script?
actually I wonder why the whole build script must contain no empty lines?, otherwise it returns:
No such file or directory
and a build fails on this place
Gitlab CI just plays shell commands so do what you do in *sh:
export ci_app_path=$(pwd)
echo "INFO: current directory: $ci_app_path"
By the time Gitlab-CI folks fix it, you may create a Makefile and export variables inside it and in Gitlab-CI pass the variables, for example
PWD=$PWD make
Makefile starts with a: export GOPATH=$(PWD)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With