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.
Update:
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?
P.S.
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, but this is the same type of issue faced withmake(perhaps that is whatgitlab ciuses?). Withmake, the idea is that if you have that many lines, you should save them to an external script and havemakeexecute it. TheMakefileis not a shell script, and should not be treated as one.gitlab cimay take the same approach.