How to merge artifacts across jobs for the same stage in Gitlab CI?

Viewed 2736

In Gitlab CI artifacts are segregated based on the jobs which generated them and hence when downloading, you can only download it on a per-job basis.

Is there a way to download all the artifacts, or pass on the artifacts to some other stage and upload from there? Basically some way to merge all the artifacts of a stage.

A possible scenario where it can be needed: Let's say in a stage deploy, I am deploying my project on 10 different servers, using 10 different parallel jobs. Each of these generates some artifacts. However, there is no way to download them all from the UI.

So does anyone know of a workaround? I am not looking for API based solution, but instead UI based or editing the CI yaml file to make it work.

1 Answers

You can create a "final" (package) stage in your pipeline which combines all the artifacts together, using the artifacts syntax.

For example:

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
Related