加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 21:47:37 所属栏目:安全 来源:网络整理
导读:我在 Gitlab CI中有一个虚拟构建脚本: pwdci_app_path=$(pwd)echo "INFO: current directory: $ci_app_path" 当系统启动构建过程时,我得到此输出: pwd/home/kai/gitlab-runners/gitlab-ci-runner/tmp/builds/project-1ci_app_path=$(pwd)echo "INFO: curre
我在 Gitlab CI中有一个虚拟构建脚本:

pwd
ci_app_path=$(pwd)
echo "INFO: current directory: $ci_app_path"

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

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:

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

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

更新:

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

脚本:

pwd
ci_app_path=$(pwd) && echo "INFO: current directory: $ci_app_path"

输出:

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

我不认为将整个脚本编写为单行是一个好主意/实践.

如何在执行构建脚本时设置变量?

附:

实际上我想知道为什么整个构建脚本必须不包含空行?否则返回:

No such file or directory

并且这个地方的构建失败了

解决方法

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

export ci_app_path=$(pwd)
echo "INFO: current directory: $ci_app_path"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读