gitlab-ci: Dynamic artifact names
Asked Answered
S

2

8

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.

  • Is there a way to use dynamic artifact name(s)?

  • Is there a reason that this artifact is also never copied in my (empty/tracked) downloads folder?

  • The above process will actually fetch a .zip file locally. Is there a way (although I have set expiration of 1 week) to have each job delete old artifacts and keep only the latest artifact / zip file?

Sensitize answered 14/11, 2017 at 10:2 Comment(0)
T
3

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

Trotter answered 14/11, 2017 at 11:24 Comment(0)
A
0

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 
Aubervilliers answered 16/5 at 7:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.