Skip to content

Sort artifacts by their jobID

umlaeute requested to merge umlaeute/gitlab-runner:artifact-order into main

What does this MR do?

This MR sorts artifacts to be downloaded by their JobID, thus extracting the artifacts in the order they were scheduled to be created, and therefore having artifacts created last overwrite files that can also be found in artifacts created in prior stages.

Why was this MR needed?

Prior, artifacts would be downloaded and extracted in an undefined order, which happened to be the last-created artifact first. As such, artifacts from later stages would be overwritten from artifacts from earlier stages.

What's the best way to test this MR?

Create a multi-stage pipeline that where each job produces artifacts with the same file. With this PR, the final stage will see files from later stages rather than from the first stage.

My example pipeline to test:

stages:
  - build
  - sign
  - deploy

.base:
  script:
    - echo ${CI_JOB_NAME} > artifact.txt
    - cat artifact.txt
  artifacts:
    name: ${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}_${CI_JOB_NAME}
    paths:
      - artifact.txt
    when: always

build:
  stage: build
  extends: .base

sign:
  stage: sign
  extends: .base

deploy:
  stage: deploy
  extends: .base
  script:
    - grep "sign" artifact.txt

What are the relevant issue numbers?

Edited by umlaeute

Merge request reports