【发布时间】:2017-12-04 18:11:33
【问题描述】:
基于此建议: Using FilePath to access workspace on slave in Jenkins pipeline 我正在尝试获取通过 git 放入工作区的文件,并使用 eachFileRecurse 通过传入调整后的文件夹来遍历这些文件。但是,当调用 FilePath 时,我得到了错误。
import groovy.io.FileType
import java.io.File
import java.lang.Object
import hudson.FilePath
import jenkins.model.Jenkins
def createFilePath(path) {
return new FilePath(Jenkins.getInstance().getComputer(env['NODE_NAME']).getChannel(), path);
}
@NonCPS // has to be NonCPS or the build breaks on the call to .each
def getFiles(dirLoc) {
def dir = new File (dirLoc)
def list = []
dir.eachFileRecurse (FileType.FILES)
{file -> if (file.name.endsWith('.txt')) {list << file}}
return list
}
我收到此错误
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.io.File(hudson.FilePath)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1737)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1537)
我无法弄清楚我在这里缺少什么来完成这项工作。提前致谢!
【问题讨论】: