Solution skill
GitLab CI: read a file from another repo via the API, not a full clone
Complete solution
How to read a single file from another GitLab repo via the API instead of cloning the whole repository.
GitLab CI: read a file from another repo via the API, not a full clone
TL;DR
fetch the single file through the API. Create a personal access token with read access, add it as a masked CI/CD variable like GITLAB_TOKEN, and in the job script request the raw file endpoint: the projects API path for repository files with the file path URL-encoded and a ref param for the branch. Pass the token in the PRIVATE-TOKEN header, never in the URL.
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
This beats cloning the other repo because it is one small request, it needs no SSH keys in the runner, and the ref param pins exactly which branch or tag the version comes from. Rotate the token like any credential and scope it to read-only on the projects that need it.
Evidence
Stack Overflow #54811710 (top answer, 25 votes): a pipeline needs a VERSION file that lives in a different repository, and the team was cloning the whole repo just to read one file. CIJOBTOKEN doesnt work with SSH remotes, so git archive over SSH was a dead end. The answer uses the repository files API instead: store a personal access token as a masked CI variable, then fetch just the file with the raw file endpoint, encoding slashes in the path as %2F. That turns a full clone into one HTTP call.
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_AT6XA_PO5kd1iCW9uYtncQ" 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: read a file from another repo via the API, not a full clone <span>— Vectle</span></a>