Skip to content

CI_JOB_TOKEN does not allow to access current project #1393

Closed
@christophedcpm

Description

@christophedcpm

Description of the problem, including code/CLI snippet

I'm a trying to list all the branch of the current repository from a CI job. To do this I expected to be able to use the CI_JOB_TOKEN present in the environment of the CI jobs, but it turns out it is not possible.

The documentation seems to indicate that it should be possible though:

The token has the same permissions to access the API as the user that triggers the pipeline. Therefore, this user must be assigned to a role that has the required privileges.

gitlab_project_id = int(os.environ["CI_PROJECT_ID"])
server_url = os.environ["CI_SERVER_URL"]
job_token = os.environ["CI_JOB_TOKEN"]
gl = gitlab.Gitlab(server_url, job_token=job_token)  
gl_project = gl.projects.get(gitlab_project_id)

Expected Behavior

CI_JOB_TOKEN should let me access the current project.

Actual Behavior

404 Not found error is raised

Specifications

  • python-gitlab version: 2.6.0
  • Gitlab server version (or gitlab.com): version: 13.7.4-ee revision: 368b4fb2eee

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions