Jenkins groovy problem with classpath - cannot resolve class

Jenkins has a Groovy script 'execution step. This step consists of two files — a client file named createWorkspaces.groovy and a bean file called WorkspaceBean.groovy. Both live in the same place in the work area.

Previously running Jenkins 1.554 ran without problems, but after upgrading to 1.594 I get 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 approved the scripts in the new script approval function, and I also added the location of the files to the class path parameter at the job stage, as well as the location of the jenkins-core.jar file.

Any ideas why this has stopped working?

+6
source share
2 answers

This seems to be a bug in the groovy plugin. Adding paths to the class path field in the plugin configuration does not change the class path.

This does not work:

Adding here does not work

Adding the CLASSPATH variable using "Injection environment variables into the build process" works.

It works:

enter image description here

+5
source

Try loading your cans dynamically. This is the final working solution I found. This sample is for the network copy folder on the local computer.

 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) 
+1
source

Source: https://habr.com/ru/post/981283/


All Articles