I am having troubles understanding how to use Job Artifacts API to access artifacts from another pipeline. I my pipeline is designed as two stages, where first is run within the pull request pipeline, and the second is run after the merge request is approved, which creates two pipelines that do not share any predefined CI/CD variables.
I am having problems referencing the branch which created the artifact. The pipelines will be triggered by different commits (CI_COMMIT_SHA), pipeline with job plan won’t have CI_COMMIT_BRANCH, while pipeline with apply will have CI_COMMIT_BRANCH=’main’. I cant find any dynamic CI variables that would be shared across the two pipelines so I can reference one trough another.
Thanks for the help
stages:
- build
- deploy
plan:
stage: build
script:
- terraform plan -out=${CI_PROJECT_DIR}/${PLAN_PATH}
artifacts:
paths:
- $PLAN_PATH
expire_in: 1 week
only:
- merge_requests
apply:
stage: deploy
script:
- 'curl --location --output artifact.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects/<project_id>/jobs/artifacts/<branch>/download?job=plan"'
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME == "main"
dinosaurdino is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.