Iha*_*dau 5 deployment yaml bitbucket bitbucket-pipelines
我有一个 bitbucket 存储库。我在 bitbucket 中有部署环境变量:
BITBUCKET_VARIABLE_PORT : 8080
Run Code Online (Sandbox Code Playgroud)
在我的bitbucket-pipelines.yaml脚本中,我可以将变量写入 .env 文件,如下所示:
<...>
step: &deploy-to-environment
name: Deploy to environment
deployment: environment
caches:
- node
script:
- echo Create .env file
- echo "PORT=$BITBUCKET_VARIABLE_PORT" > .env
- cat .env
<...>
Run Code Online (Sandbox Code Playgroud)
但我想避免重写 .env 文件的整行。
是否可以执行以下操作?
<...>
PORT=<BITBUCKET_VARIABLE_PORT>
HOST=<BITBUCKET_VARIABLE_HOST>
<...>
Run Code Online (Sandbox Code Playgroud)
<...>
step: &deploy-to-environment
name: Deploy to environment
deployment: environment
caches:
- node
script:
- <replace_placeholders_here_in_script>
<...>
Run Code Online (Sandbox Code Playgroud)
您可以使用 sed 替换 .env 文件中的字符串
sed -i "s/BITBUCKET_VARIABLE_PORT/...xxxx.../" .env
sed -i "s/BITBUCKET_VARIABLE_HOST/...hostname.../" .env
Run Code Online (Sandbox Code Playgroud)
您还可以使用变量进行替换
MYPORT=XXX
sed -i "s/BITBUCKET_VARIABLE_PORT/$MYPORT/" .env
Run Code Online (Sandbox Code Playgroud)