Access artifact in next task to deploy

Hello everyone,

I’ve recently started with GitLab and setup the following tasks in my gitlab-ci.yml:

  • task build
  • task deploy_test
  • task deploy_production

Now my task build creates an artifact(jar) which I can download from the UI but I want to access this artifact in my deploy_test and deploy_production. In https://docs.gitlab.com/ee/ci/yaml/README.html#dependencies I read that artifacts are automatically available in the next job if that job depends the job creating the artifact. But how do I access it? I want to grab this artifact and use it in my deploying task.

Thanks in regards for any help provided,

Falko

Believe that I found the solution, when adding dependencies to a task all artifacts created by that task are downloaded and extracted in the build folder used by the next runner as documented in https://docs.gitlab.com/ee/user/project/pipelines/job_artifacts.html.

1 Like

Another way, you can describe dependencies in .gitlab-ci.yml
https://docs.gitlab.com/ee/ci/yaml/#dependencies
May be it will be useful for googlers

The artifacts are extracted in the working directory of the runner, which is also where your Git repository is checked out. So you don’t have to look for a special build directory, or an artifacts.zip archive, it’s just right there in front of you.

So if you have a repository like this:

.gitlab-ci.yml
file.java

And your build job turns it into this:

.gitlab-ci.yml
file.java
build/
    archive.jar
libs/
    file.class

And you only specify build/ in the artifacts (of this first job), then your artifacts.zip will contain this:

build/
    archive.jar

And for the next job you will start with this structure:

.gitlab-ci.yml
file.java
build/
    archive.jar

Which is your Git repository, with the artifacts.zip unzipped in it.

It selects all artifacts from jobs from previous stages, unless you define dependencies, then you can select from which jobs you want to re-use the artifacts. You can use this to skip downloading artifacts you don’t need, or to make jobs in the same stage sequential (otherwise they might run in parallel).

2 Likes

Hey, I recently started working with GitLab and I have already created a project. In my project, I’m executing TestNG automation and generating artifacts. As @falko2010 mentioned I also want to access my testNG-results file in deploy stage and read data from that file. How Can I read the file from there? And, In deploy job’s log, I can see “Downloading artifacts for test:run (566998574)…” But How do I access the results file which downloaded from previous stage?

1 Like