Search code examples
pythongitlabgitlab-ci-runner

Error pulling packages from gitlab private repository in CI job


As part of a gitlab CI job, I am using pip to install internally-developed packages that are stored using gitlab pypi. When I attempt to run pip install <PACKAGE_NAME>, I get the following error:

WARNING: 401 Error, Credentials not correct for https://<GITLAB_URL>/api/v4/projects/<PROJECT_ID>/packages/pypi/simple/<PACKAGE_NAME>/
ERROR: Could not find a version that satisfies the requirement <PACKAGE_NAME> (from versions: none)
ERROR: No matching distribution found for <PACKAGE_NAME>

I am using a pip.conf file like the following:

[global]
extra-index-url =
    https://__token__:<CI_JOB_TOKEN_SUBBED_IN_EXTERNALLY>@<GITLAB_URL>/api/v4/projects/<PROJECT_ID>/packages/pypi/simple

The install using the same pip.conf works fine on a workstation using my personal api token instead of the CI Job token. What might be causing this problem?


Solution

  • It turns out that while __token__ works fine for personal tokens, it does not work for CI tokens; it needs to be gitlab-ci-token. The following file works fine:

    [global]
    extra-index-url =
        https://gitlab-ci-token:<CI_JOB_TOKEN_SUBBED_IN_EXTERNALLY>@<GITLAB_URL>/api/v4/projects/<PROJECT_ID>/packages/pypi/simple