---
title: "Use GitLab Artifact in Chained Pipelines"
date: 2022-08-15T15:07:19.000Z
author: Z.SHINCHVEN
tags: [GitLab, CI/CD]
canonical: https://atlassc.net/2022/08/15/use-gitlab-artifact-in-chained-pipelines
---
## Build and Download Artifact

GitLab CI/CD job can [archive result as an artifact](https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#create-job-artifacts) that can be accessed from [API](https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#access-the-latest-job-artifacts-by-url).

### Artifact GitLab Runner Config

```yaml
compile: # Job name
  artifacts:
    paths:
      - dist # Artifact path
    expire_in: 1 week # Artifact expiration time
```

### Download 

```bash
# Download artifact with job name
curl --request GET -sL \
     --header "JOB-TOKEN: $CI_JOB_TOKEN" \
     --url 'https://<GITLAB_HOST>/api/v4/projects/<PROJECT_ID>/jobs/artifacts/<BRANCH_NAME>/download?job=<JOB_NAME>' \
     --output './artifact.zip'
# Unzip artifact
unzip artifact.zip
```

## Downstream Jobs

GitLab pipeline can be triggered using [trigger API](https://docs.gitlab.com/ee/ci/triggers/) and can have downstream jobs when you need a few CI/CD jobs be chained.

```bash
curl --request POST \
     --form token=${CI_JOB_TOKEN} \
     --form ref=<BRANCH_NAME> \
     --form 'variables[<VAR_NAME>]=<VAR_VALUE>' \
     --url 'https://<GITLAB_HOST>/api/v4/projects/<PROJECT_ID>/trigger/pipeline'
```

## Token Access

GitLab repository now requires project scope permission to access artifact in CI Job using `CI_JOB_TOKEN`.

Go to your source project `Settings`, `CI/CD Settings`, in the `Token Acess` area, add your downstream project to `Project with access` list.
