gitlab-plugin icon indicating copy to clipboard operation
gitlab-plugin copied to clipboard

Jenkins 2.2xx reporting a 401 error when token provided from gitlab.

Open ghost opened this issue 4 years ago • 4 comments

Issue

I have gitlab 13.5.2-ee on our internal network.

I have two build servers: The old one (Jenkins 2.190.3, CSRF protection turned off, plugins: git 4.0.0, git client, 3.0.0, gitlab plugin 1.5.13).

The new one (Jenkins 2.249.2, CSRF not turned off, default crumb issuer, enable proxy compatibility, plugins: git 4.4.5, git client: 3.5.1, gitlab api, 1.0.6, gitlab authentication: 1.10, gitlab branch source: 1.5.1, gitlab logo plugin: 1.0.5, gitlab merge request builder: 2.0.0, gitlab plugin: 1.5.13).

The old one can accept a url like this on push-to-the-repo to run unit tests: http://<machineName>:8080/job/<projectName>/

The new one gets a "403 No valid crumb" error for the same url.

Fair enough, CSRF and all that.

The readme for gitlab plugin seems pretty clear here: https://github.com/jenkinsci/gitlab-plugin

(Even if there's no 'Show API Token' button, as there are no Legacy tokens.)

I should:

  • In an account that can build create an API token in Jenkins (done).
  • copy the userID from above and the token to the url hit on the new machine:

http://<userID>:@<machineName>:8080/job/<projectName>/

looks like "1826463627266737..."

(Leaving the Secret Token field empty.)

Now, when gitlab runs, it returns a 401 "Invalid token".

Look in the logs, and it just says: Jan 18, 2021 2:11:01 PM INFO com.dabsquared.gitlabjenkins.webhook.GitLabWebHook getDynamic WebHook called with url: /project/<projectName>

Search in the readme, find the 'Getting help'. Follow those instructions. Still get the 401, still the same error message in the recorder, but it also shows the json data sent for the request...but no errors.

So, any other suggestions about why Jenkins is returning a 401?

Context

  • Gitlab plugin version: X.Y.Z
  • Gitlab version: 13.5.2-ee
  • Jenkins version: X.Y.Z
  • Job type: Pipeline, Freestyle, Matrix, etc.

Logs & Traces

Please include any relevant log that could serve to better understand the source of your issue For Jenkins Gitlab Plugin logs, follow instruction in User Support section. For Gitlab logs, ask an administrator to provide you the relevant Gitlab logs.

Problem description

Describe your problem in a meaningful way:

  • what were you doing (simple push, merge request, MR with fork, ...)
  • what was expected
  • what occurred finally

ghost avatar Jan 19 '21 16:01 ghost

Hello, have you resolved this issue? I get the same issue here

JH-scourse avatar Apr 07 '21 08:04 JH-scourse

Nope, haven't resolved the issue.

It's rather disappointing.

ghost avatar Apr 07 '21 09:04 ghost

I get the same issue here

HTTP ERROR 401 Invalid token

URI: /project/test
401
Invalid token
Stapler

Powered by Jetty:// 9.4.42.v20210604

haohetao avatar Sep 21 '21 15:09 haohetao