When to store artifacts, based on success or failure

Artifact paths to upload, based on success or failure

We are building code in CI. When the job fails we would like to upload error-logs. When the job succeeds the logs are not needed (they take too much time to upload)

Is it possible in GitLab CI to specify what artifacts to upload on failure?

Current artifacts:

artifacts:
    name: "${CI_PROJECT_NAME}"
    paths:
        - *.json
        - compiled-image
        - some-other-image
        - error.log

This leads to error.log only being uploaded when the pipeline succeeds. We can solve it by using when: always, but we do not want error.log when the job succeeds.

Wanted artifacts:

artifacts:
    name: "${CI_PROJECT_NAME}"
    when: on_success
    paths:
        - *.json
        - compiled-image
        - some-other-image
    when: on_failure
    paths:
        - error.log

Is there a correct syntax for making this work?

1 Like

I don’t think it’s possible to split up the artifacts like this in a single job. There should be only one paths list, and all the other metadata (when, etc.) applies to that.

There is an issue for adding this feature. Please do up-vote it and make a comment, this will make it more likely to be scheduled for implementation.

1 Like