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

No credentials found for credentialsId

Open MarcJose opened this issue 4 years ago • 20 comments

Issue

Context

  • Gitlab plugin version: 1.5.13
  • Gitlab version: 12.3.5 (2417d5becc7)
  • Jenkins version: 2.190.1
  • Job type: Freestyle

Logs & Traces

17:16:32 ERROR: Build step failed with exception
17:16:32 java.lang.IllegalStateException: No credentials found for credentialsId: 
17:16:32 	at com.dabsquared.gitlabjenkins.connection.GitLabConnection.getApiToken(GitLabConnection.java:134)
17:16:32 	at com.dabsquared.gitlabjenkins.connection.GitLabConnection.getClient(GitLabConnection.java:116)
17:16:32 	at com.dabsquared.gitlabjenkins.connection.GitLabConnectionConfig.getClient(GitLabConnectionConfig.java:92)
17:16:32 	at com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.getClient(GitLabConnectionProperty.java:37)
17:16:32 	at com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.getClient(GitLabConnectionProperty.java:45)
17:16:32 	at com.dabsquared.gitlabjenkins.publisher.MergeRequestNotifier.perform(MergeRequestNotifier.java:31)
17:16:32 	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
17:16:32 	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
17:16:32 	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
17:16:32 	at hudson.model.Build$BuildExecution.post2(Build.java:186)
17:16:32 	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
17:16:32 	at hudson.model.Run.execute(Run.java:1840)
17:16:32 	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
17:16:32 	at hudson.model.ResourceController.execute(ResourceController.java:97)
17:16:32 	at hudson.model.Executor.run(Executor.java:429)
17:16:32 Build step 'Add note with build status on GitLab merge requests' marked build as failure
17:16:32 ERROR: Build step failed with exception
17:16:32 java.lang.IllegalStateException: No credentials found for credentialsId: 
17:16:32 	at com.dabsquared.gitlabjenkins.connection.GitLabConnection.getApiToken(GitLabConnection.java:134)
17:16:32 	at com.dabsquared.gitlabjenkins.connection.GitLabConnection.getClient(GitLabConnection.java:116)
17:16:32 	at com.dabsquared.gitlabjenkins.connection.GitLabConnectionConfig.getClient(GitLabConnectionConfig.java:92)
17:16:32 	at com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.getClient(GitLabConnectionProperty.java:37)
17:16:32 	at com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty.getClient(GitLabConnectionProperty.java:45)
17:16:32 	at com.dabsquared.gitlabjenkins.publisher.MergeRequestNotifier.perform(MergeRequestNotifier.java:31)
17:16:32 	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
17:16:32 	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
17:16:32 	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
17:16:32 	at hudson.model.Build$BuildExecution.post2(Build.java:186)
17:16:32 	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
17:16:32 	at hudson.model.Run.execute(Run.java:1840)
17:16:32 	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
17:16:32 	at hudson.model.ResourceController.execute(ResourceController.java:97)
17:16:32 	at hudson.model.Executor.run(Executor.java:429)
17:16:32 Build step 'Add vote for build status on GitLab merge requests' marked build as failure

Problem description

I added "Add note with build status on GitLab merge requests" and "Add vote for build status on GitLab merge requests" to my Freestyle Job as Post-build Actions. But when the job gets triggered by a comment in the Merge request I receive the error above. The project itself gets cloned though via the connection and the build itself is executed. Am I missing anything here or is that a bug?

MarcJose avatar Oct 10 '19 18:10 MarcJose

This happened to me as well. Upon inspecting the job's config.xml file in Jenkins, I found that the following lines were added for some reason.

<jobCredentialId/>
<useAlternativeCredential>false</useAlternativeCredential>

See below for the location in the config file.

<com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty plugin="[email protected]">
  <gitLabConnection>GitLab</gitLabConnection>
  <jobCredentialId/>
  <useAlternativeCredential>false</useAlternativeCredential>
</com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty>

Manually deleting both lines and restarting Jenkins solved the problem for me. I think the culprit is the empty jobCredentialId field. Another potential solution to this problem is changing the job config to use alternative credentials for GitLab and then selecting the main credentials that were already setup. In doing so, the jobCredentialId changes from <jobCredentialId/> to <jobCredentialId>redacted</jobCredentialId>.

Next up is to track down why this is happening and fix it.

danieleagle avatar Oct 07 '20 21:10 danieleagle

same error , delete same code to fix

sicode avatar Mar 16 '21 09:03 sicode

Run into this myself as well

db0 avatar Mar 17 '21 14:03 db0

Ran into this issue today as well. I run two jenkins environments. While the problem was only experienced in one of them, the config above existed in both environments. The environment where i experienced the problem is running jenkins 2.284 & gitlab plugin 1.5.19. The environment which did not have an issue is running jenkins 2.277.1 (stable) & gitlab plugin 1.5.19.

The troubled environment was just patched to 2.284 yesterday.

Aarex1 avatar Mar 23 '21 15:03 Aarex1

Ditto, just had to manually edit jobs/*/config.xml and remove those two lines in order to restore webhook functionality. Jenkins 2.287 Gitlab Plugin 1.5.20

rdica avatar Apr 12 '21 13:04 rdica

Same issue and solution.

Jenkins 2.287 GitLab Plugin 1.5.20

jsolbrig avatar Apr 14 '21 16:04 jsolbrig

Same issue and solution.

Jenkins 2.249,3 GitLab Plugin 1.5.20

yuliycv avatar Apr 21 '21 11:04 yuliycv

I have two jobs. Both with the same xml settings. One working, one not. The fix worked fine on the one that wasn't working. Very odd!

andrewducker avatar Apr 29 '21 09:04 andrewducker

Good! Same issue and solution.

Jenkins 2.291 GitLab Plugin 1.5.20

HsiangLeekwok avatar May 07 '21 03:05 HsiangLeekwok

Same issue here. Started when upgrading to Jenkins 2.277.3 from 2.266.something. I can go check the exact version from which I upgraded from.

theCrius avatar May 10 '21 11:05 theCrius

Same issue. Jenkins 2.277.4, GitLab Plugin 1.5.20

ubaranouski avatar May 16 '21 18:05 ubaranouski

Thanks, Same issue and solved. Jenkins 2.277.4, GitLab Plugin 1.5.20

padepokan79dev avatar May 17 '21 07:05 padepokan79dev

Got bit by this today after upgrading to the latest jenkins core + latest gitlab plugin.

Jenkins 2.293 gitlab-plugin: 1.5.20

ganthore avatar May 21 '21 14:05 ganthore

Just happened to me, provided solution worked. I needed to apply solution to all existing jobs in jenkins, applying just to the one I was testing did not work.

marcosmko avatar May 26 '21 14:05 marcosmko

Thanks! This helped a lot!

Since you mentioned the <useAlternativeCredential>false</useAlternativeCredential> setting, I decided to give the UI another try. In my case, I was able to check 'Use alternative credential' and then selected the same "Gitlab API Key" I already had choosen globally in the plugin section of the "Configure System" page. This worked for me without modifying the config file.

Dashboard -> Select Job -> Configure -> Use alternative credential -> Select Key

sanhup avatar Jun 03 '21 18:06 sanhup

Same issue, same workaround, thx!

Jenkins 2.300 Gitlab Plugin 1.5.20

cinlloc avatar Jun 24 '21 08:06 cinlloc

Also had this issue

Jenkins 2.277.2 Gitlab 1.5.20

zjhuntin avatar Jul 02 '21 17:07 zjhuntin

Also had this Issue Jenkins 2.289.3 Gitlab 1.5.20

Janfy avatar Aug 12 '21 16:08 Janfy

I had the same issue, but didn't have possibility to edit config.xml in filesystem.

I have found that this can be also edited in GUI also:

  • select job detail
  • click "Use alternative credential" just below Gitlab connection dropdown
  • select valid Gitlab API key

kowy avatar Aug 25 '21 13:08 kowy

Same problem and same solution. Jenkins 2.303.1 Gitlab 13.11.2

Here is how to do it in pipeline : properties([gitLabConnection(gitLabConnection: 'Gitlab Forge', jobCredentialId: '8ec138a7-465e-41ec-8281-e930d0ad4505', useAlternativeCredential: true)])

jhippolyte avatar Sep 30 '21 15:09 jhippolyte