0

I have a job which is maintained by a team, let's call it docs. It runs in a pipeline with jobs maintained by other teams. If the docs team job succeeds, I want to download artifact regardless of the other jobs which impact the pipeline status. An example of this is as follows,

#!/bin/sh
mkdir foo;
cd foo;
git init;
glab repo create;

GLCI=.gitlab-ci.yml
cat > "$GLCI" <<'EOF'
image: alpine:latest
stages:
  - build

fail:
  stage: build
  script:
    - exit 42 # failure

build:
  stage: build
  script:
    - mkdir dist
    - echo "0" > dist/bar.txt
  artifacts:
    expire_in: 5 seconds
    paths:
      - dist/*

EOF

#commit ci
git add "$GLCI";
git commit -m 'Add gitlab ci';
git branch --set-upstream-to=main
git push --set-upstream -o ci.skip origin main;

echo bump > test.txt
git add test.txt
git commit -a -m'bump';
git push;

In the above we have two jobs in a pipeline, build (which passes) and fail (which fails). I want to download the last build job's artifact factoring in nothing but the job status.

Job status

The end point, Download a single artifact file from specific tag or branch in the Artifacts API almost does what I want, but it only triggers on successful pipelines,

Download a single artifact file for a specific job of the latest successful pipeline for the given reference name from inside the job’s artifacts archive. The file is extracted from the archive and streamed to the client, with the plain/text content type.

How can I work around this limitation? How can this be done?

1 Answer 1

0

Workarounds

Because we don't (yet) have an API to download the last artifact produced by a successful job by name there are two options here to work around this limitation,

  1. Restructure your CI: the end-points assume that only successful pipelines produce artifacts that are saved. You're fighting an uphill battle with a pipeline that can fail, but succeed in producing something you want.

  2. Crawl the jobs for the project, something like this

    curl "https://gitlab.acme.net/api/v4/projects/1571/jobs?access_token=TOKEN"
      | jq '.[] | select(.status=="success" and .name=="build")'
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.