[JIRA] (JENKINS-52266) Unable to use credentials in groovy class

2 views
Skip to first unread message

simon.vanderveldt@gmail.com (JIRA)

unread,
Jun 29, 2018, 3:18:03 AM6/29/18
to jenkinsc...@googlegroups.com
Simon van der Veldt created an issue
 
Jenkins / Bug JENKINS-52266
Unable to use credentials in groovy class
Issue Type: Bug Bug
Assignee: Daniel Spilker
Components: job-dsl-plugin
Created: 2018-06-29 07:17
Environment: jobdsl 1.67
Priority: Minor Minor
Reporter: Simon van der Veldt

We'd like to make use of credentials stored in Jenkins from a groovy class that's part of our job DSL scripts. Unfortunately this seems to be impossible since 1.43 (couldn't actually find a reference to this in the code/changelog, but did find this SO answer https://stackoverflow.com/a/40474755 ) because it's impossible to import the necessary classes.

This simple example:

def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(    com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class,    Jenkins.instance,    null,    null);for (c in creds) {     println(c.id": " + c.description)}

from https://wiki.jenkins.io/display/JENKINS/Printing+a+list+of+credentials+and+their+IDs

works fine in the script console but fails when putting it in a job DSL script.

This means the only way for us to provide these credentials is as hardcoded strings in our job DSL scripts, which is of course not acceptable.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

mail@daniel-spilker.com (JIRA)

unread,
Jul 3, 2018, 3:08:03 PM7/3/18
to jenkinsc...@googlegroups.com

simon.vanderveldt@gmail.com (JIRA)

unread,
Jul 3, 2018, 3:34:01 PM7/3/18
to jenkinsc...@googlegroups.com
Simon van der Veldt commented on Bug JENKINS-52266
 
Re: Unable to use credentials in groovy class

I created this issues after reading that page multiple times and trying out different things, none of which work.

The latter 2 options are insecure, so obviously not an option and the 1st one is the reason I created this issue, credentials() only works in certain places like when defining a git remote, not everywhere/in groovy classes.

simon.vanderveldt@gmail.com (JIRA)

unread,
Jul 3, 2018, 3:35:02 PM7/3/18
to jenkinsc...@googlegroups.com
Simon van der Veldt edited a comment on Bug JENKINS-52266
I created this issues after reading that page multiple times and trying out different things, none of which work.

The latter 2 options are insecure, so obviously not an option and the 1st one is the reason I created this issue, {{credentials()}} only works in certain places like when defining a git remote, not everywhere/in groovy classes.


Would the linked issue solve this problem?
Judging by it's age I guess I shouldn't hold my breath ;)

simon.vanderveldt@gmail.com (JIRA)

unread,
Jul 3, 2018, 3:36:02 PM7/3/18
to jenkinsc...@googlegroups.com
Simon van der Veldt edited a comment on Bug JENKINS-52266
I created this issues after reading that page multiple times and trying out different things, none of which work.

The latter 2 options are insecure, so obviously not an option and the 1st one is the reason I created this issue, {{credentials()}} only works in certain places like when defining a git remote, not everywhere/in groovy classes.

Would the linked issue solve this problem?
Judging by it's age I guess I shouldn't hold my breath ;)

simon.vanderveldt@gmail.com (JIRA)

unread,
Jul 3, 2018, 3:37:01 PM7/3/18
to jenkinsc...@googlegroups.com
Simon van der Veldt edited a comment on Bug JENKINS-52266
I created this issues after reading that page multiple times and trying out different things, none of which work.

The latter 2 options are insecure, so obviously not an option and the 1st one is the reason I created this issue, {{credentials()}} only works in certain places like when defining a git remote, not everywhere/in groovy classes.

Would the linked issue solve this problem?
Judging by it's age I guess I shouldn't hold my breath? ; It seems easier to just make {{credentials( ) }} work everywhere?

simon.vanderveldt@gmail.com (JIRA)

unread,
Jul 3, 2018, 3:37:02 PM7/3/18
to jenkinsc...@googlegroups.com
Simon van der Veldt edited a comment on Bug JENKINS-52266
[~daspilker]

I created this issues after reading that page multiple times and trying out different things, none of which work.

The latter 2 options are insecure, so obviously not an option and the 1st one is the reason I created this issue, {{credentials()}} only works in certain places like when defining a git remote, not everywhere/in groovy classes.

Would the linked issue solve this problem?
It seems easier to just make {{credentials()}} work everywhere?

mail@daniel-spilker.com (JIRA)

unread,
Jul 3, 2018, 4:22:03 PM7/3/18
to jenkinsc...@googlegroups.com
Daniel Spilker closed an issue as Duplicate
 
Change By: Daniel Spilker
Status: Resolved Closed

zechtitus@hotmail.com (JIRA)

unread,
May 15, 2019, 3:04:01 PM5/15/19
to jenkinsc...@googlegroups.com
David Laidlaw commented on Bug JENKINS-52266
 
Re: Unable to use credentials in groovy class

I found I was running into same issue - the groovy script worked fine when testing with the in script editor.
what made it finally work for me was adding 'import jenkins.model.*' to top of script - viola all my calls with the 

 
com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials
were working again

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)
Reply all
Reply to author
Forward
0 new messages