Problem
Due diligence:
artifact fetching
artifact dependency
artifact docs
gitlab issue for artifacts
and many more. I will limit since often posts have a set number of links allowed.
Gitlab Version
We have the gitlab saas and premium so no feature issues.
The problem I am trying to solve, which seems like it should be fairly easy, is to access artifacts created in pipeline one
in a build_job
from pipeline two
in a release_job
. Build job creates artifacts like so:
build_package:
...
artifacts:
paths:
- dist/
branch flow:
O ____________ ____________
_|_ push | | MR | |
| ------> | branch one | ----->| branch two |
/ \ |____________| |____________|
| |
| |
v |
artifact <- needs artifact
“Solutions” Seen
Needs
I have seen people say they use a needs
somewhat like this:
release_job:
needs:
- project: $PROJECT_WITH_ARTIFACTS
job: $JOB_THAT_CREATES_ARTIFACTS
ref: $BRANCH_NAME_WITH_ARTIFACTS
artifacts: true
this is usually when referencing a pipeline’s artifacts in a different project, but it is said that you can use your same project in the - project:
parameter. However, in my case branch one
would always be a different ref:
so I am unsure how branch two
would get that dynamic information. It is likely I am not understanding something simple, but I couldn’t get this to work even when I tried hardcoding the ref:
with the ref name known ahead of time.
Artifacts API
The api docs show how you can download the artifacts archive:
'curl --location --output artifacts.zip "https://gitlab.example.com/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/main/download?job=test&job_token=$CI_JOB_TOKEN"'
again, you need to know dynamic information in that curl call since branch one
would have a different ref name on every new branch push.
both the needs
and the API suffer from me being unable to know the branch one
’s ref name.
Is There a Canonical Way?
In Gitlab is there a canonical way to access artifacts from earlier pipelines in the same project?
Using the API seems like a roundabout way to do it since your CI/CD pipeline is in the project with your artifacts that are all accessible.
Any help is greatly appreciated. If more information is needed please ask and I am open to other suggestions that would accomplish the same thing like changing branch strategy or something else.
Thank you.