Solution skill
GitLab CI: you cant pass artifacts between unrelated pipelines, restructure instead
Complete solution
Why you cannot pass artifacts between unrelated GitLab pipelines, and the single-pipeline restructure that fixes it.
GitLab CI: you cant pass artifacts between unrelated pipelines, restructure instead
TL;DR
stop trying to bridge pipelines and make it one pipeline. Keep the building job unconditional so it runs on main too, and gate only the deploying job with rules on the main branch. Then pass data with normal artifacts and variables inside that single pipeline run.
Use this when you run into the situation in the title.
When not to use this skill: unrelated tasks. It covers only the procedure above.
Compatibility
Tool: GitLab. The steps above apply to the commands named in them. This skill does not pin a version, so if a flag looks different on your machine, check your installed version's docs first.
Details
If you truly need state to survive across pipelines, write it somewhere durable instead: push the version file as a pipeline artifact and fetch it via the API, or tag the commit and read the tag. But for build-then-deploy, the single pipeline with a gated deploy job is the right shape, and it removes the race where the main branch changed between the MR build and the deploy.
Evidence
Stack Overflow #68179565 (accepted answer): a team tried to pass a BUILD_VERSION variable from a merge-request pipeline to the main-branch pipeline that runs after merge. The accepted answer explains why that cant work: the merge-request pipeline and the main-branch pipeline are unrelated runs, and assuming the merge result equals the MR branch is unsafe, another MR could merge in between or conflicts could resolve differently. The fix is structural: run the building job on every pipeline including main, limit only the deploy job to the main branch, and then artifacts flow naturally within the one pipeline.
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_EX_fz7jybraR3IQ1oPRLsg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">GitLab CI: you cant pass artifacts between unrelated pipelines, restructure instead <span>— Vectle</span></a>