GitLab 动态 运行 并行作业
GitLab Dynamically run jobs in parallel
我有一个项目,它在遵循特定约定的文件夹中生成 go main 文件。问题是当有代码推送时,我需要在 Gitlab CI 管道中并行构建这些项目,并且我无法在 .gitlab-ci.yml
中对它们进行硬编码,因为它们是动态生成的。我需要并行构建这些 go 项目,并且如果所有单个项目构建都成功,则需要通过构建阶段。有人可以让我知道在 Gitlab 中是否可行。
不幸的是,gitlab CI 似乎不支持这个 https://gitlab.com/gitlab-org/gitlab-ce/issues/23455。正如本期和@Jakub 中提到的,我正在寻找类似的东西(一些 glob 或模板类的解决方案),以便我可以在运行中并行化作业:
build_%:
image: dnd
stage: build
glob: microservices/*/Dockerfile
context: microservices/{1}
script:
- docker build {1}
parallel: true
所以我决定暂时使用 go templates,直到 Gitlab CI 提供一个解决方案。
我太期待了...否则将不得不开始研究 jenkins job DSL 插件。
现在也可以使用 child pipelines feature。
您可以使用 YTT 为子管道生成 YAML 配置文件 - 但只要您提供有效的 YAML 文件,就可以使用任何生成方法。
.gitlab-ci.yml
generate-config:
stage: build
script: ytt -f config-template.yml -f config-template-values.yml --data-value-yaml services="[${SERVICES}]" > generated-config.yml # with SERVICES=service1,service2
artifacts:
paths:
- generated-config.yml
child-pipeline:
stage: test
trigger:
include:
- artifact: generated-config.yml
job: generate-config
config-template.yml
#@ load("@ytt:data", "data")
stages:
- test
#@ for service in data.values.services:
#@yaml/text-templated-strings
(@= service @)-test:
stage: test
script:
- #@ "test " + service
#@ end
config-template-values.yml
#@data/values
---
services: []
我有一个项目,它在遵循特定约定的文件夹中生成 go main 文件。问题是当有代码推送时,我需要在 Gitlab CI 管道中并行构建这些项目,并且我无法在 .gitlab-ci.yml
中对它们进行硬编码,因为它们是动态生成的。我需要并行构建这些 go 项目,并且如果所有单个项目构建都成功,则需要通过构建阶段。有人可以让我知道在 Gitlab 中是否可行。
不幸的是,gitlab CI 似乎不支持这个 https://gitlab.com/gitlab-org/gitlab-ce/issues/23455。正如本期和@Jakub 中提到的,我正在寻找类似的东西(一些 glob 或模板类的解决方案),以便我可以在运行中并行化作业:
build_%:
image: dnd
stage: build
glob: microservices/*/Dockerfile
context: microservices/{1}
script:
- docker build {1}
parallel: true
所以我决定暂时使用 go templates,直到 Gitlab CI 提供一个解决方案。
我太期待了...否则将不得不开始研究 jenkins job DSL 插件。
现在也可以使用 child pipelines feature。 您可以使用 YTT 为子管道生成 YAML 配置文件 - 但只要您提供有效的 YAML 文件,就可以使用任何生成方法。
.gitlab-ci.yml
generate-config:
stage: build
script: ytt -f config-template.yml -f config-template-values.yml --data-value-yaml services="[${SERVICES}]" > generated-config.yml # with SERVICES=service1,service2
artifacts:
paths:
- generated-config.yml
child-pipeline:
stage: test
trigger:
include:
- artifact: generated-config.yml
job: generate-config
config-template.yml
#@ load("@ytt:data", "data")
stages:
- test
#@ for service in data.values.services:
#@yaml/text-templated-strings
(@= service @)-test:
stage: test
script:
- #@ "test " + service
#@ end
config-template-values.yml
#@data/values
---
services: []