【发布时间】:2021-06-25 23:22:27
【问题描述】:
我正在为 gitlab ci/cd 变量而苦苦挣扎。我看到很多相互矛盾的例子。总之,我想知道的是如何在脚本内外使用变量。
例如,在作业配置中,我可以使用 bash 命令在脚本部分中分配一个变量吗?
some-job:
variables:
SOME_VAR: ''
script:
- SOME_VAR = $(<file_with_a_line_of_text.txt)
在上述情况下,我不确定我是否可以这样做。但我需要用文件内容(即工件)填充一个变量。另外,什么时候在变量前面使用“$”?我看到使用这些格式的一些示例:
"SOME_VAR" #in quotes, no dollar sign
"${SOME_VAR}" #in quotes, with dollar sign and wrapped with curly braces
${SOME_VAR} #no quotes, with dollar sign and wrapped with curly braces
$SOME_VAR #i.e. without the double quotes or curly braces
SOME_VAR #i.e. without the double quotes, dollar sign, and curly braces
我可以在示例中看到如此多的用法变化,但并不真正知道何时使用每种样式。而且我在网上找不到一个使用 bash 命令在脚本中设置自定义变量的示例。
【问题讨论】:
-
也许你应该从shell介绍开始?
标签: bash shell gitlab gitlab-ci