Groovy 缺少 属性 异常
Groovy Missing Property Exception
我有一个 jenkins 构建需要获取变更集中签入的所有文件的文件名。
我已经在从机上安装了groovy,并配置了Jenkins来使用。我是 运行 下面的脚本,应该 return 名称(或者我假设这也可能是错误的)并打印到控制台屏幕但是我收到此错误:
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 的新手,所以如果它的语法有问题或者我遗漏了一个步骤,请告诉我。
我不知道你使用的 jenkins
的版本,但是根据你可以找到的 ChangeSet
的源代码 here 我建议你替换行 [=13] =] 与:
def affectedFiles = items.collect { it.getAffectedPaths() }
// or with the equivalent more groovy-idiomatic version
def affectedFiles = items.collect { it.affectedPaths }
如果还有更多问题,请随时评论答案。
我有一个 jenkins 构建需要获取变更集中签入的所有文件的文件名。
我已经在从机上安装了groovy,并配置了Jenkins来使用。我是 运行 下面的脚本,应该 return 名称(或者我假设这也可能是错误的)并打印到控制台屏幕但是我收到此错误:
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 的新手,所以如果它的语法有问题或者我遗漏了一个步骤,请告诉我。
我不知道你使用的 jenkins
的版本,但是根据你可以找到的 ChangeSet
的源代码 here 我建议你替换行 [=13] =] 与:
def affectedFiles = items.collect { it.getAffectedPaths() }
// or with the equivalent more groovy-idiomatic version
def affectedFiles = items.collect { it.affectedPaths }
如果还有更多问题,请随时评论答案。