avatar

ShīnChvën ✨

Effective Accelerationism

Powered by Druid

Use GitLab Artifact in Chained Pipelines

Mon Aug 15 2022

Build and Download Artifact

GitLab CI/CD job can archive result as an artifact that can be accessed from API.

Artifact GitLab Runner Config

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

Download

# 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 and can have downstream jobs when you need a few CI/CD jobs be chained.

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'