CI_JOB_TOKEN can't download folder from the repository as archive.zip ("The remote server returned an error: (404) Not Found.")
Hi team. I use gitlab_runner to run pipelines in one repository, and I load files from another repository during the pipeline. Until recently, I used a private-token to download files from one (private) repository to another (private). The script looks like this:
$WebClient = New-Object System.Net.WebClient
$WebClient.Headers.Set("PRIVATE-TOKEN", $env:MY_PRIVATE_TOKEN)
$url = "https://gitlab.com/api/v4/projects/12345/repository/archive.zip?path=path_to_folders"
$archivename = "test.zip"
$WebClient.DownloadFile($url, $archivename)
In simple language, it should look something like this:
wget --header="PRIVATE-TOKEN: $env:MY_PRIVATE_TOKEN" https://gitlab.com/api/v4/projects/12345/repository/archive.zip?path=path_to_folders"
So everything worked fine until I changed my private-token to ci_job_token using this gitlab documentation.
I enabled "Token Access" from one repository to second.
Modified script:
$WebClient = New-Object System.Net.WebClient
$WebClient.Headers.Set("JOB-TOKEN", $env:CI_JOB_TOKEN)
$url = "https://gitlab.com/api/v4/projects/12345/repository/archive.zip?path=path_to_folders"
$archivename = "test.zip"
$WebClient.DownloadFile($url, $archivename)
In simple language, it should look something like this:
wget --header="JOB-TOKEN: $env:CI_JOB_TOKEN" https://gitlab.com/api/v4/projects/12345/repository/archive.zip?path=path_to_folders"
My gitlab_runner gets: "The remote server returned an error: (404) Not Found."
I assume from the gitlab documentation that my gitlab_runner is not authorized.
When I'm try:
git clone https://gitlab-ci-token:${env:CI_JOB_TOKEN}@gitlab.com/my_project_name/project.git
My gitlab_runner successfully downloads the entire repository.
There is another place in my script where I download artifacts jobs from the same repository. It looks like the same but I'm use another endpoint (/jobs/artifacts/master/download?job=maps):
$WebClient = New-Object System.Net.WebClient
$WebClient.Headers.Set("JOB-TOKEN", $env:CI_JOB_TOKEN)
$url = "https://gitlab.com/api/v4/projects/12345/jobs/artifacts/master/download?job=maps"
$archivename = "artifacts.zip"
$WebClient.DownloadFile($url, $archivename)
In simple language, it should look something like this:
wget --header="JOB-TOKEN: $env:CI_JOB_TOKEN" https://gitlab.com/api/v4/projects/12345/jobs/artifacts/master/download?job=maps"
My gitlab_runner successfully downloads the entire repository.
Could you please tell me if I am using the wrong API? Or maybe is it impossible to download certain files at once in a zip archive using ci_job_token? Or I'm doing something wrong?
I'm use gitlab_runner on windows host.
Version: 15.5.1
Git branch: 15-5-stable
OS/Arch: windows/amd64
Many Thanks!
@gitlab-bot label typebug CI job token devopscreate Category:Runner pipeline failure