Gitlab: How to use artifacts in subsequent jobs after build

Viewed 22179

I've been trying to make a GitLab CI/CD pipeline for deploying my MEAN application. I have three stages: 1. test 2. build 3. deploy

The build stage has a build_angular job which generates an artifact. Now I want to use this artifacts in the next stage i.e deploy. The deploy job tells me that it has downloaded the artifact(image has been attached), but now I want to extract this artifact, but I don't know where the artifact is being downloaded.

The path where the artifact is being downloaded is not mentioned anywhere in the docs. if

2 Answers

GitLab is cleaning the working directory between two subsequent jobs. That's why you have to use artifacts and dependencies to pass files between jobs.

When the "deploy" job says that the build artifact have been downloaded, it simply means that they have been recreated as they were before. The location of the downloaded artifacts matches the location of the artifact paths (as declared in the .yml file).

Example

build_job:
  stage: build
  script:
  - echo "create bin/ directory"
  - make
  artifacts:
    paths:
      - bin/

deploy_job:
  stage: deploy
  script:
  - ls bin/
  dependencies:
  - build_job

Directory bin/ is passed to deploy_job from build_job.

Note that gitlab-org/gitlab-runner issue 2656 mentions:

But the documentation talks about this limitation in fact : "in the latest pipeline that succeeded" : no way now to get artifacts from the currently running pipeline.

Thank you !
I think the documentation should really make it more obvious that you need the whole pipeline to complete before the artifact is accessible and that you can't use this within the pipeline.

It seemed to me that the obvious usecase of this feature would be deploying on the server, and that you'd want server deployment to be part of the pipeline.

That comes from Pipelines / Jobs Artifacts / Downloading the latest artifacts

To download a single file from the artifacts use the following URL:

https://example.com/<namespace>/<project>/-/jobs/artifacts/<ref>/raw/<path_to_file>?job=<job_name>

See allpix-squared/allpix-squared as an example.

Its .gitlab-ci.yml deploy stage calls a script with the right path:

sudo -u cvclicdp -i $RUNNER_LOCATION/.gitlab-ci.d/gitlab_deploy.sh $RUNNER_LOCATION $BUILD_PATH
Related