I have an 'Execute Groovy script' build step in Jenkins. This step consists of two files - a client file called createWorkspaces.groovy and a bean file called WorkspaceBean.groovy. Both live in the same location in the job workspace.
Previously running Jenkins 1.554 this ran without issues, but after upgrading to 1.594 I am getting the following error:
/jenkins/workspace/testjob/scripts/groovy/createWorkspaces.groovy: 75: unable to resolve class WorkspaceBean
@ line 75, column 21.
def workspace = new WorkspaceBean()
^
1 error
I have approved the scripts in the new script approval function and I have also added the location of the files to the class path parameter in the job step as well as the location of the jenkins-core.jar file.
Any ideas why this has stopped working?
This appears to be a bug in the groovy plugin. Adding paths to the Class path field within the plugin configuration does not change the class path.
This does not work:
Adding a CLASSPATH variable via the 'Inject environment variables into the build process' plugin does work.
This works:
Try to load your jars dynamically. This is the final working solution I found. This sample is for copy network folder to local machine.
def file = new File("jcifs-1.3.18.jar")
this.class.classLoader.rootLoader.addURL(file.toURI().toURL())
def auth_server = Class.forName("jcifs.smb.NtlmPasswordAuthentication").newInstance("domain", "username", "password")
def auth_local = Class.forName("jcifs.smb.NtlmPasswordAuthentication").newInstance(null, "local_user", "password")
def source_url = args[0]
def dest_url = args[1]
def auth = auth_server
//prepare source file
if(!source_url.startsWith("\\\\"))
{
source_url = "\\\\localhost\\"+ source_url.substring(0, 1) + "\$" + source_url.substring(1, source_url.length());
auth = auth_local
}
source_url = "smb:"+source_url.replace("\\","/");
def source = Class.forName("jcifs.smb.SmbFile").newInstance(source_url,auth_server)
//prepare destination file
if(!dest_url.startsWith("\\\\"))
{
dest_url = "\\\\localhost\\"+ dest_url.substring(0, 1) + "\$" +dest_url.substring(2, dest_url.length());
auth = auth_local
}
dest_url = "smb:"+dest_url.replace("\\","/");
def dest = Class.forName("jcifs.smb.SmbFile").newInstance(dest_url,auth_local)
source.copyTo(dest)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.