[英]Cross using yml variables in the bash script
Below I have shown my .gitlab-ci.yml file:下面我展示了我的 .gitlab-ci.yml 文件:
variables:
timezone: "Europe/Vienna"
stages:
- style
- build
style:
stage: style
script:
- sudo docker run --rm -v $PWD:/code omercnet/pycodestyle
build:
stage: build
script:
blla blla
- sudo docker exec ${CI_PROJECT_PATH_SLUG} /bin/bash -c "./install.sh"
blla blla
Next, it is my install.sh script:接下来是我的 install.sh 脚本:
#!/bin/bash
blla blla
echo -e "\nmx_download_url: https://dl.bintray.com/random" >> /etc/random-installer/setup.yml
sed -i s+old text+new text+g etc/random-installer/setup.yml
blla blla
How I can use the value of the variable timezone from the yml file in the new text in the bash script?如何在 bash 脚本的新文本中使用来自 yml 文件的变量timezone的值?
timezone
is visible as environment variable for the gitlab jobs, however install.sh
scripts is running from another context - it's executed by docker. timezone
作为 gitlab 作业的环境变量可见,但是install.sh
脚本从另一个上下文运行 - 它由 docker 执行。 Docker itself has access to $timezone
, however containers it's operating with don't. Docker 本身可以访问$timezone
,但是它运行的容器不能。
To solve your problem you can explicitly pass it:要解决您的问题,您可以明确传递它:
- sudo docker exec -e TIMEZONE=$timezone ${CI_PROJECT_PATH_SLUG} /bin/bash -c "./install.sh"
This will set environment variable $TIMEZONE
for install.sh inside the container.这将为容器内的 install.sh 设置环境变量$TIMEZONE
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.