Nicole Phillips
Nicole Phillips

Reputation: 763

Groovy Missing Property Exception

I have a jenkins build that needs to get the filenames for all files checked in within a changeset.

I have installed groovy on the slave computer and configured Jenkins to use it. I am running the below script that should return the names (or so I assume as this may be wrong as well) and print to the console screen however I am getting this error:

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

Here is the Groovy System Script:

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
}

I am very new to Groovy and Jenkins so if its syntax issue or if I'm missing a step please let me know.

Upvotes: 1

Views: 1688

Answers (1)

Giuseppe Ricupero
Giuseppe Ricupero

Reputation: 6272

I don't know the version of jenkins you are using but according to the sourcecode of ChangeSet that you can find here I suggest you to replace line 9 with:

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

Feel free to comment the answer if there will be more issues.

Upvotes: 1

Related Questions