Jenkins groovy class路径问题 - 无法解决 class

Jenkins groovy classpath issue - unable to resolve class

我在 Jenkins 中有一个 'Execute Groovy script' 构建步骤。此步骤包含两个文件 - 一个名为 createWorkspaces.groovy 的客户端文件和一个名为 WorkspaceBean.groovy 的 bean 文件。两者都位于作业工作区的相同位置。

以前 运行 Jenkins 1.554 这个 运行 没有问题,但升级到 1.594 后我收到以下错误:

/jenkins/workspace/testjob/scripts/groovy/createWorkspaces.groovy: 75: unable to resolve class WorkspaceBean 
 @ line 75, column 21.
       def workspace = new WorkspaceBean()
                       ^

1 error

我已经在新的脚本批准功能中批准了脚本,我还在作业步骤中的 class 路径参数中添加了文件的位置以及 jenkins-core.jar 文件。

知道为什么它停止工作了吗?

这似乎是 groovy 插件中的错误。在插件配置中向 Class 路径字段添加路径不会更改 class 路径。

这行不通:

通过 'Inject environment variables into the build process' 插件添加 CLASSPATH 变量确实有效。

这个有效:

尝试动态加载您的 jar。这是我找到的最终工作解决方案。此示例用于将网络文件夹复制到本地计算机。

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)