pkaramol
pkaramol

Reputation: 19322

gitlab-ci: Dynamic artifact names

I am running a gitlab-ci job that will fetch locally a file from a remote server, more or less as follows:

retrieve_docs:
    stage: fetch_docs
    image: debian:jessie
    script:
      - ssh $USERNAME@$SERVER /perform/some/work
      - INSTFILE=$(ssh $USERNAME@$SERVER bash -c 'find /root -iname "somepattern*" | tail -n 1 | xargs readlink -f')
      - echo "Will retrieve locally $INSTFILE"
      - scp $USERNAME@$SERVER:$INSTFILE .
      - BASEFILE=$(basename $INSTFILE)
      - mv $BASEFILE downloads/
    artifacts:
      name: $BASEFILE
      paths:
        - downloads/

The above job definition however does not seem to work, as the BASEFILE variable is rendered as empty when providing the filename.

Upvotes: 8

Views: 13108

Answers (2)

MortenB
MortenB

Reputation: 3529

The paths: keyword supports wildcards:

  artifacts:
    name: "some description"
    when: always
    paths:
    - ./*.xlsx

This was taken from a scheduled job that generates a report in excel. So if it successfully run it will exist an *.xlsx file in the working directory

From the runners console log:

./*.xlsx: found 1 matching artifact files and directories 

Upvotes: 0

Kalpa Gunarathna
Kalpa Gunarathna

Reputation: 1107

For example if you use something like CI_JOB_ID CI_JOB_NAME you can have dynamic artifact names per JOB. You can have a combination of varibales defined in https://docs.gitlab.com/ee/ci/yaml/README.html#artifacts-name to get dynamic artifact names for your stage or job or pipeline.

Normally in a job, git lab compresses whatever specified in the path and upload it to the runner manager so that the next job can download the artifacts from the runner manager. If the job fails you cant upload any artifacts to other jobs. Do a find . and check wether the required dirs are there. You can use when option to continue the pipline no matter it fails or not. See https://docs.gitlab.com/ee/ci/yaml/README.html#artifacts-when

Yes you can expire the artifcat at your timers. See https://docs.gitlab.com/ee/ci/yaml/README.html#artifacts-expire_in

Upvotes: 3

Related Questions