It took me a while to figure this one out, the docs online were pretty thin, so I'm putting this here to help the next person who gets stuck.

There are 2 tricks here.

  1. It's not clear how to get the workspace in GroovyAxis. It has to be accessed through the 'context' object, but is null when the script is run when the job is saved. It is populated when the job is built.
  2. The workspace exists on the slave node, but the Groovy script is run on the master. You must use the FilePath object to correctly access the files on the slave

 

import hudson.FilePath

def workspace = context?.build?.workspace

if (null == workspace) {
    return ['noworkspace'] // avoid returning 'default' so the user has a chance of figuring out what went wrong
}

def configDir = workspace.toString() + '/openpower/configs/'

def dir = new FilePath(workspace.channel, configDir)

def files = []
dir.list().each {
    def name = it.getName()
    if (name.endsWith('_defconfig')) {
        files << name.replace('_defconfig', '')
    }
}

return files