如何在Gitlab CI中的构建脚本中设置(环境)变量?

sta*_*tic 6 bash continuous-integration build environment-variables gitlab

我有一个虚拟构建脚本Gitlab CI:

pwd
ci_app_path=$(pwd)
echo "INFO: current directory: $ci_app_path"
Run Code Online (Sandbox Code Playgroud)

当系统启动构建过程时,我得到此输出:

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:
Run Code Online (Sandbox Code Playgroud)

所以变量没有设置(或者只为该行设置:因为我知道每行单独执行)

我听说推送/弹出机制达到我想要的功能,但找不到任何细节,如何实现.

更新:

正如我想的那样,每一行都是分别执行的.所以变量范围只有一行,它定义了:

脚本:

pwd
ci_app_path=$(pwd) && echo "INFO: current directory: $ci_app_path"
Run Code Online (Sandbox Code Playgroud)

输出:

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

and a build fails on this place

Jak*_*nia 7

Gitlab CI只是播放shell命令,所以你在*sh中做了什么:

export ci_app_path=$(pwd)
echo "INFO: current directory: $ci_app_path"
Run Code Online (Sandbox Code Playgroud)


小智 1

当 Gitlab-CI 人员修复它时,您可以创建一个 Makefile 并在其中导出变量,然后在 Gitlab-CI 中传递变量,例如

PWD=$PWD 使

Makefile 以:export GOPATH=$(PWD) 开头