代码之家  ›  专栏  ›  技术社区  ›  Nicole Phillips

Groovy缺少属性异常

  •  1
  • Nicole Phillips  · 技术社区  · 6 年前

    我有一个jenkins构建,需要获取在变更集中签入的所有文件的文件名。

    我在从机上安装了groovy,并配置Jenkins使用它。我正在运行下面的脚本,该脚本应返回名称(或者我认为这也可能是错误的),并打印到控制台屏幕,但我遇到了此错误:

    groovy.lang.MissingPropertyException: No such property: paths for class: hudson.plugins.tfs.model.ChangeSet
    

    下面是Groovy系统脚本:

    import hudson.plugins.tfs.model.ChangeSet
    
    // work with current build
    def build = Thread.currentThread()?.executable
    
    // get ChangesSets with all changed items
    def changeSet= build.getChangeSet()
    def items = changeSet.getItems()
    def affectedFiles = items.collect { it.paths }
    
    // get file names
    def fileNames = affectedFiles.flatten().findResults
    fileNames.each {
        println "Item: $it" // `it` is an implicit parameter corresponding to the current element
    }
    

    我对Groovy和Jenkins非常陌生,所以如果它的语法有问题或者我遗漏了一个步骤,请告诉我。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Giuseppe Ricupero    6 年前

    我不知道 jenkins 您正在使用,但根据的源代码 ChangeSet 你能找到的 here 我建议您更换线路 9 使用:

     def affectedFiles = items.collect { it.getAffectedPaths() }
     // or with the equivalent more groovy-idiomatic version
     def affectedFiles = items.collect { it.affectedPaths }
    

    如果有更多问题,请随时评论答案。