【问题标题】:Jenkins - Groovy pipeline - Using FilePath gives Could not find matching constructorJenkins - Groovy 管道 - 使用 FilePath 给出找不到匹配的构造函数
【发布时间】: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)

我无法弄清楚我在这里缺少什么来完成这项工作。提前致谢!

【问题讨论】:

    标签: jenkins groovy


    【解决方案1】:

    没有以 hudson.FilePath 作为参数的 java.io.file 的构造函数。

    请参阅以下链接的 java 文档:https://docs.oracle.com/javase/7/docs/api/java/io/File.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 2020-01-14
      • 2022-06-16
      • 2016-01-26
      • 2016-06-17
      • 2018-01-19
      相关资源
      最近更新 更多