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

时间:2020-09-22 05:48:19

标签: continuous-integration gitlab devops gitlab-ci

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

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

可能需要的场景:假设在阶段部署中,我正在使用10个不同的并行作业在10个不同的服务器上部署我的项目。这些中的每一个都会产生一些伪像。但是,无法从用户界面下载所有内容。

那么有人知道解决方法吗?我不是在寻找基于API的解决方案,而是在基于UI或编辑CI yaml文件以使其正常工作。

1 个答案:

答案 0 :(得分:0)

您可以在管道中创建一个“最终”(打包)阶段,该阶段使用artifacts语法将所有工件组合在一起。

例如:

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