gpt4 book ai didi

gitlab - .gitlab-ci.yml yaml 中的数组变量

转载 作者:行者123 更新时间:2023-12-05 00:43:30 54 4
gpt4 key购买 nike

我想在我的 gitlab ci/cd yml 文件的变量中使用数组,类似这样:

variables:
myarrray: ['abc', 'dcef' ]
....
script: |
echo myarray[0] myarray[1]

但 Lint 告诉我文件不正确:

variables config should be a hash of key value pairs, value can be a hash

我尝试了下一个:

variables:
arr[0]: 'abc'
arr[1]: 'cde'
....
script: |
echo $arr[0] $arr[1]

但是构建失败并打印出 bash 错误:

bash: line 128: export: `arr[0]': not a valid identifier

有没有办法在.gitlab-ci.yml 文件中使用数组变量?

最佳答案

根据docs ,这是你应该做的:

It is not possible to create a CI/CD variable that is an array of values, but you can use shell scripting techniques for similar behavior.

For example, you can store multiple variables separated by a space in a variable, then loop through the values with a script:

job1:
variables:
FOLDERS: src test docs
script:
- |
for FOLDER in $FOLDERS
do
echo "The path is root/${FOLDER}"
done

关于gitlab - .gitlab-ci.yml yaml 中的数组变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70006905/

54 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com