如何在Gitlab CI中为同一阶段跨作业合并工件



在Gitlab中,CI工件是根据生成它们的作业进行隔离的,因此在下载时,您只能根据每个作业进行下载。

有没有一种方法可以下载所有的工件,或者将工件传递到其他阶段并从那里上传?基本上是合并一个阶段的所有工件的某种方法。

一个可能需要它的场景:假设在一个阶段部署中,我正在10个不同的服务器上部署我的项目,使用10个不同并行作业。每一个都会生成一些工件。但是,没有办法从UI中全部下载它们。

有人知道变通办法吗?我不是在寻找基于API的解决方案,而是基于UI或编辑CIyaml文件使其工作。

您可以创建一个;最后的";(package(阶段,它使用工件语法将所有工件组合在一起。

例如:

stages:
- build
- package
.artifacts_template:
artifacts:
name: linux-artifact
paths:
- "*.txt"
expire_in: 5 minutes
build:linux-1:
extends: .artifacts_template
stage: build
script:
- touch hello-world-linux-1.txt
build:linux-2:
extends: .artifacts_template
stage: build
script:
- touch hello-world-linux-2.txt
build:linux-3:
extends: .artifacts_template
stage: build
script:
- touch hello-world-linux-3.txt
package:
stage: package
script:
- echo "packaging everything here"
needs:
- build:linux-1
- build:linux-2
- build:linux-3
artifacts:
name: all-artifacts
paths:
- "*.txt"
expire_in: 1 month

您可以使用parallel:matrix多次触发一个作业,然后在另一个作业中收集工件。

例如:

deploystacks:
stage: deploy
script:
- bin/deploy --target $PROVIDER
parallel:
matrix:
- PROVIDER: [aws, ovh, gcp, vultr]
environment: production/$PROVIDER
artifacts:
paths:
- result/$PROVIDER
collectArtifacts:
stage: collect
script:
- processArtifacts <[aws, ovh, gcp, vultr]>
needs:
- job: deploystacks
artifacts: true

上面的示例将为provider中定义的每个提供程序创建deployStacks作业。

最新更新