What I got so far is, it is possible to Authenticate with Personal Access Token
and include external CI script but a cleaner approach would be to get access using $CI_JOB_TOKEN
since it is more secure and restricted. I am looking into if it can be done this way -
include 'https://gitlab-ci-token:${CI_JOB_TOKEN}@raw-file-url'
I have tried to curl in this format in a dummy script job, but it fails to fetch the file.
Apparently, an external script can be imported using file API and $CI_JOB_TOKEN (https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/2346/diffs), but I am looking into if include
feature also support this. Any suggestion on how to achieve that is appreciated.
Unfortunately, CI_JOB_TOKEN
is very limited in scope. As of today (GitLab 11.0), you can only do two things with it:
References:
So you cannot use CI_JOB_TOKEN
to download a file from another repository, neither via the raw endpoint (/raw/<ref>/<path>
) nor the API.
Unfortunately, deploy keys don't help either -- they are only for SSH.
The only workable solution I've come up with is to use a separate user:
Reporter
role./profile/personal_access_tokens
) for that user with api and read_repository rights.BUILD_USER_TOKEN
.$BUILD_USER_TOKEN
in your CI script to access the API or project files.This is a huge hack, and I really hope to see GitLab make CI_JOB_TOKEN
a first-class, read-only (?) token with rights to specified resources.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With