Jenkins-凹槽管道 - 使用FilePath提供找不到匹配的构造函数



在此建议上构建:使用filepath访问詹金斯管道(Jenkins Pipeline)的从属上的工作空间,我试图通过git将文件掉入工作区中,并通过调整后的文件夹中的每个文件来遍历这些文件。但是,当召集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)

我无法弄清楚我在这里缺少什么来完成这项工作。预先感谢!

java.io.file没有hudson.filepath作为参数。

请参阅以下链接的Java Doc:https://docs.oracle.com/javase/7/docs/api/java/io/file.html

最新更新