arrays - 如何将 GitLab CI 变量设置为 gitlab-ci 中的数组?

标签 arrays bash gitlab gitlab-ci

我想使用 variables: 关键字创建一个 gitlab 变量,其中包含要传递给 GitLab dependencies: 关键字的依赖项数组。结构看起来像:

variables:
    DEPENDENCY_LIST: ["dependency1", "dependency2", "dependency3"]

dependencies: "$DEPENDENCY_LIST"

但是上面的代码给出了一个 YAML 错误,指出“jobs:source code dependency should be an array of strings”

如何将 GitLab CI 变量的值设置为 .gitlab-ci.yml 作业中的数组?

最佳答案

How do you set a GitLab CI variable to an array in gitlab-ci?

你不能 - 环境变量的格式是名称=值。没有数组。

使用 yaml anchor 。

.dependency_list: &dependency_list
   - dependency1
   - dependency2
   - dependency3

dependencies: *dependency_list

但是 gitlab-ci 不会展平依赖项中的嵌套数组,因此无法合并两个数组。

请参阅 gitlab ci 文档。

关于arrays - 如何将 GitLab CI 变量设置为 gitlab-ci 中的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68106375/

相关文章:

java - TestNG 断言中的运行时问题

php - 将 php 输出保存在文件中

regex - 如何使用 bash 和正则表达式排除单词列表中的单词?

linux - 在 stderr 上打印消息的 Bash 命令

azure - 使用 PowerShell 将代码从 GitLab 存储库部署到 Azure Web App

c - 我在哪里处理我不拥有的内存? (字符数组)

java - 比较字符串数组的数组列表

linux - 为什么这个 Bash 代码在我退出屏幕之前不会运行?

r - 尝试安装私有(private) Gitlab R 包时由对等方重置连接

docker - GitLab 与 Docker Swarm + 初始 root 密码 : can't log in