9

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

1
  • I'm not familiar with gitlab, but this is the same type of issue faced with make (perhaps that is what gitlab ci uses?). With make, the idea is that if you have that many lines, you should save them to an external script and have make execute it. The Makefile is not a shell script, and should not be treated as one. gitlab ci may take the same approach. Commented Oct 14, 2013 at 12:34

2 Answers 2

10

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"
Sign up to request clarification or add additional context in comments.

Comments

1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.