首页 > 解决方案 > Windows Jenkins master 无法在 Linux 代理上正确执行作业

问题描述

我有一个 Jenkins 安装,其中主机是 Windows 机器,它的一个代理在 Linux 上运行。我需要在 Linux 上显式运行一项作业,但是当 Jenkins 调用管道外部的方法时,它认为该方法应该在主(Windows)机器上执行,因此我看到了错误。

'''
node ('Linux Machine'){ // I specified that this should be run on Linux
    slurper = new JsonSlurper().parse ('my_file_on_linux') //all is good
    builder = new JsonBuilder (slurper) // use builder to modify my JSON file
    builder.context.module = modifyModule ()
}
@NonCPS
def modifyModule () {
    new File(workspace).eachFileRecurse(FILES){ // workspace here is WINDOWS JENKINS MASTER ROOT DIRECTORY :( Exception
    // search for some files...
}
}
'''

错误是(注意其将 Linux 路径(/bigdisk0/jenkins/workspace/... 转换为 Windows 格式):java.io.FileNotFoundException: D:\bigdisk0\jenkins\workspace\consul-devcoreserver\MyModule at org.codehaus.groovy .runtime.ResourceGroovyMethods.checkDir(ResourceGroovyMethods.java:1043) at org.codehaus.groovy.runtime.ResourceGroovyMethods.eachFileRecurse(ResourceGroovyMethods.java:1122) at org.codehaus.groovy.runtime.dgm$942.doMethodInvoke(Unknown Source) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213) 在 groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022) 在 org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:47)

标签: jsonjenkinsjenkins-pipelinejenkins-groovy

解决方案


推荐阅读