- Notifications
You must be signed in to change notification settings - Fork673
Closed
Labels
Description
Description of the problem, including code/CLI snippet
The following python3 snippet fails running under Gitlab 13.12.5-ee CI pipeline:
importos,gitlabgl=gitlab.Gitlab(os.environ['CI_SERVER_URL'],job_token=os.environ['CI_JOB_TOKEN'],user_agent='Whatever/custom-name')gl.auth()
It's using python-gitlabv2.10.1
and it fails with:
Traceback (most recent call last): File "/builds/CbQEQmZ2/0/whatever/tools/project_name/./app.py", line 3, in <module> gl.auth() File "/usr/local/lib/python3.10/site-packages/gitlab/client.py", line 257, in auth self.user = self._objects.CurrentUserManager(self).get() File "/usr/local/lib/python3.10/site-packages/gitlab/exceptions.py", line 304, in wrapped_f return f(*args, **kwargs) File "/usr/local/lib/python3.10/site-packages/gitlab/mixins.py", line 146, in get server_data = self.gitlab.http_get(self.path, **kwargs) File "/usr/local/lib/python3.10/site-packages/gitlab/client.py", line 662, in http_get result = self.http_request( File "/usr/local/lib/python3.10/site-packages/gitlab/client.py", line 622, in http_request raise gitlab.exceptions.GitlabAuthenticationError(gitlab.exceptions.GitlabAuthenticationError: 401: 401 Unauthorized
The.gitlab-ci.yml
config is as follows:
stages: -runrun:stage:runrules: -if:'$CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE == "web"' -if:'$CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE == "schedule"'image:python:alpinebefore_script: -pip3 install -r requirements.txtscript: -python3 app.py# This is where the snippet lives
Expected Behavior
Asthe documentation says, the following code should be valid:
importgitlab# job token authentication (to be used in CI)importosgl=gitlab.Gitlab('http://10.0.0.1',job_token=os.environ['CI_JOB_TOKEN'])# make an API request to create the gl.user object. This is mandatory if you# use the username/password authentication.gl.auth()
Actual Behavior
Thegl.auth()
method fails with aGitlabAuthenticationError
exception.
Specifications
- python-gitlab version: v2.10.1
- API version you are using (v3/v4): v4
- Gitlab server version (or gitlab.com): 13.12.5-ee