Different artifacts when job succeeded and failed with GitLab CI

Viewed 1671

Need to upload artifact binary.bin when job succeeded and build_trace.log when failed.

Looking on artifacts:when I don't see such ability.

Is there some tricky hack?

I would like to see something like

job:
  artifacts:
    - name: failed_trace_log
      when: on_failure
      paths:
      - build_trace.log
    - name: succeed
      when: on_success
      paths:
      - binary.bin

Current workaround is:

job:
  artifacts:
    when: always
    paths:
    - build_trace.log
    - binary.bin
1 Answers

One alternative is to use when:on_failure in a cleanup job after the first.

stages:
  - build
  - cleanup_build

job:
  stage: build
  script:
    - make build
  artifacts:
    paths:
      - binary.bin

cleanup_job:
  when: on_failure
  stage: cleanup_build
  script:
    - do cleanup
  artifacts:
    paths:
      - build_trace.log
Related