How to access artifacts in next stage in GitLab CI/CD

Viewed 52

I am trying to build GitLab CI/CD for the first time. I have two stages build and deploy The job in the build stage produce artifacts. And then the job in deploy stage wants to upload those artifacts to AWS S3. Both the jobs are using same runner but different docker image.

default:  
  tags:
    - dev-runner
stages:         
  - build
  - deploy

build-job:      
  image: node:14
  stage: build
  script:
    - npm install
    - npm run build:prod    
  artifacts:
    paths:
      - deploy/build.zip


deploy-job:      
  image: docker.xx/xx/gitlab-templates/awscli
  stage: deploy  
  script:    
    - aws s3 cp deploy/build.zip s3://mys3bucket

The build-job is successfully creating the artifacts. GitLab documentation says artifacts will be automatically downloaded and available in the next stage, however it does not specify where & how these artifacts will be available to consume in the next stage.

Question
In the deploy-job will the artifacts available at the same location? like deploy/build.zip

1 Answers

The artifacts should be available to the second job in the same location, where the first job saved them using the 'artifacts' directive.

I think this question already has an answer on the gitlab forum:

https://forum.gitlab.com/t/access-artifact-in-next-task-to-deploy/9295

Maybe you need to make sure the jobs run in the correct order using the dependencies directive, which is also mentioned in the forum discussion accesible via the link above.

Related