gitlab-plugin
gitlab-plugin copied to clipboard
Error "API Token for GitLab access required" on configuration UI but connection successful
Context
- Gitlab plugin version: 1.5.13
- Gitlab version: 13.2.2
- Jenkins version: 2.235.5
Problem description
- I have created a Jenkins credential of type "GitLab API Token" with a token that I created for a user on the GitLab instance.
- In "Manage Jenkins" > "Configure System", section "Gitlab", I check "Enable authentication for '/project' end-point", enter a name for the connection, enter the URL for the GitLab instance and select the credential in the list. I click the "Test connection" button and all is good.
- The problem is that each time that I go again to "Manage Jenkins" > "Configure System", section "Gitlab", the error "API Token for GitLab access required" appears, when the credential for the GitLab API Token is selected and in fact clicking the "Test Connection" button works as expected. See attached image.

Investigating the source code of the plugin, the "API Token for Gitlab access required" message is defined in https://github.com/jenkinsci/gitlab-plugin/blob/master/src/main/resources/com/dabsquared/gitlabjenkins/connection/Messages.properties and used in the doCheckApiTokenId method of the DescriptorImpl class in the GitLabConnection.java file (https://github.com/jenkinsci/gitlab-plugin/blob/master/src/main/java/com/dabsquared/gitlabjenkins/connection/GitLabConnection.java). The error is shown when the value is null or empty:
Searching the history of that method, I found this: https://github.com/jenkinsci/gitlab-plugin/commit/090fa9a546a9bce06a8791abd245172bc2f20612?branch=090fa9a546a9bce06a8791abd245172bc2f20612&diff=split, when that method was in the GitLabConnectionConfig.java file and contained this comment (line 92) that disappeared in the commit:
// TODO check why this gets called twice on page load once with the correct id and once with an empty string
So, the comment disappeared but apparently the same (or a variation) is still happening: the page loads with an empty string, the error is shown, but somehow then it gets the value and therefore the Test Connection button works.
This is happening in two Jenkins instances (with the same versions, though).
Up, some problem will wait PR