Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

  • 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?

like image 661
pkaramol Avatar asked Nov 14 '17 10:11

pkaramol


People also ask

What is artifacts in GitLab CI?

Artifacts are files created as part of a build process that often contain metadata about that build's jobs like test results, security scans, etc. These can be used for reports that are displayed directly in GitLab or can be published to GitLab Pages or in some other way for users to review.

Where are GitLab CI artifacts stored?

The artifacts are stored by default in /home/git/gitlab/shared/artifacts . Save the file and restart GitLab for the changes to take effect.

What is Ci_job_token?

CI_JOB_TOKEN: A token to authenticate with certain API endpoints. The token is valid as long as the job is running.


1 Answers

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

like image 104
Kalpa Gunarathna Avatar answered Sep 18 '22 15:09

Kalpa Gunarathna