Cannot import Credentials plugin classes after upgrade from 1.44 to 1.48

883 views
Skip to first unread message

James S.

unread,
Jul 22, 2016, 12:38:14 PM7/22/16
to job-dsl-plugin
Hi, we have a groovy script that we call with the Job DSL plugin which imports some classes from the Credentials plugin:

import com.cloudbees.plugins.credentials.CredentialsProvider
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials
...

This works fine in version 1.44 of the Job DSL plugin, but the moment I upgrade to the latest version 1.48 I start getting errors:

Processing DSL script develop.groovy
ERROR: startup failed:
workspace:/jobs/SaltTests.groovy: 1: unable to resolve class com.cloudbees.plugins.credentials.CredentialsProvider
 @ line 1, column 1.
   import com.cloudbees.plugins.credentials.CredentialsProvider
   ^

workspace:/jobs/SaltTests.groovy: 2: unable to resolve class com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials
 @ line 2, column 1.
   import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials
   ^

2 errors


I've done some searching here and in the release notes and could not find anything related.
I also noticed this warning message in the Jenkins plugin management page, but I am not sure if it is related?

Warning: the new version of this plugin claims to use a different settings format than the installed version. Jobs using this plugin may need to be reconfigured, and/or you may not be able to cleanly revert to the prior version without manually restoring old settings. Consult the plugin release notes for details.

How can I import these classes using the 1.48 version of the Job DSL plugin? 
Any ideas on what is going on?

Thanks,
James

James S.

unread,
Jul 26, 2016, 10:29:33 AM7/26/16
to job-dsl-plugin
I'm not that familiar with Groovy but I understand a classpath is set before the Job DSL runs the Groovy code.

Given that the import succeeds in 1.44 but fails on 1.48, it would seem the 1.44 Job DSL plugin automatically includes other plugin classes in the classpath whereas the 1.48 does not.
Can anyone confirm whether that's the case?

Thanks

Daniel Spilker

unread,
Aug 8, 2016, 6:28:48 PM8/8/16
to job-dsl...@googlegroups.com
Prior to 1.48 the Job DSL plugin had a dependency to the Folders plugin. That made the classes from the Folders plugin visible in the DSL.

The dependency has been removed in 1.48 as stated in the release notes. Thus you can't use the classes from the Folders plugin anymore.

Why do you need to import the classes?

Daniel

--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugin+unsubscribe@googlegroups.com.
To post to this group, send email to job-dsl-plugin@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/2e0d34cd-1699-428f-ab6e-eceb168800dd%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Phil Hindman

unread,
Aug 11, 2016, 8:34:33 AM8/11/16
to job-dsl-plugin
I've run into the same sort of problem and found a workaround, but ultimately think I found a better way to do what I wanted.

The reason I import the CredentialsProvider is to get some named credentials (that define a P4 server/username pair) and then use those credentials in other places (e.g. interpolate cred.getUsername() and cred.getP4port() into a batchfile step that runs a few perforce commands).  I was already getting the P4BaseCredentials class in a roundabout way:
   def p4credClass = Jenkins.instance.getDescriptor('org.jenkinsci.plugins.p4.credentials.P4PasswordImpl').clazz.getSuperclass()
and found that I could do something similar to get the CredentialsProvider class:
   def credProvider = Jenkins.instance.getDescriptor('com.cloudbees.plugins.credentials.UserCredentialsProvider').clazz.getSuperclass()

But this seems kind of hacky/brittle, and I think I found a better way to do what I need by using a groovy script to set environment variables for the subsequent steps, i.e.

job('example') {
    environmentVariables {
        groovy('''
            import com.cloudbees.plugins.credentials.CredentialsProvider
            import org.jenkinsci.plugins.p4.credentials.P4BaseCredentials

            def p4cred = CredentialsProvider.findCredentialById(
               'our-credential-id',
               P4BaseCredentials,
               currentBuild);

            return [P4PORT: p4cred.getP4port(),P4USER: p4cred.getUsername()]
        ''')
    }
    steps {
        batchFile("echo %P4PORT% -- %P4USER%")
    }
}

So, hopefully that helps...

-phil
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.

James S.

unread,
Aug 15, 2016, 9:30:33 PM8/15/16
to job-dsl-plugin
We needed to programatically check whether a given credential was defined or not in the Credentials Plugin.
We ended up restructuring our code/job setup in such a way so we wouldn't need to access the classes directly.

Cheers
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages