Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamically setting artifact path/folder structure on gitlab-ci.yml

I have the following gitlab-ci.yml file that reads the package.json using the jq processor to dynamically set the variable name of the artifact folder, something along the lines of

image: node:latest

stages:
 - build

before_script:
    ## steps ignored for purpose of question
    - export NAME_OF_ARTIFACT_FOLDER=$(cat package.json | jq -r .name)"_"$(cat package.json | jq -r .version)".zip"
    - echo $NAME_OF_ARTIFACT_FOLDER ##prints the expected name here eg. myApp_1.0.0.zip

prod_build:
  stage: build
  script:
   - echo $NAME_OF_ARTIFACT_FOLDER ##prints the expected name here eg. myApp_1.0.0.zip
   - yarn run build
  artifacts:
    paths:
    - dist/$NAME_OF_ARTIFACT_FOLDER ## this does not work
    expire_in: 2 hrs

The issue here is - dist/$NAME_OF_ARTIFACT_FOLDER does not work, not sure if am missing something here.

EDIT

Upon hard coding the expected path such as the following, it works fine, which would mean that the folder name is valid and that the artifact is indeed identified appropriately, but does NOT work when coming from $NAME_OF_ARTIFACT_FOLDER

 artifacts:
    paths:
    - dist/myApp_1.0.0.zip ##hardcoding the expected works just fine
    expire_in: 2 hrs
like image 741
Jaya Avatar asked Apr 04 '18 01:04

Jaya


People also ask

Where are artifacts stored GitLab ci?

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 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.

How long GitLab keep artifacts?

Default artifacts expiration The default expiration time of the job artifacts can be set in the Admin Area of your GitLab instance. The syntax of duration is described in artifacts:expire_in and the default value is 30 days .


1 Answers

Well, that is not possible currently. Manual says as follows:

The artifacts:name variable can make use of any of the predefined variables.

That is no variables set in your script part of the job can be used.

like image 198
Jakub Kania Avatar answered Oct 02 '22 21:10

Jakub Kania