Search code examples
jenkinsgroovyplugins

Jenkins Active Choices Parameter groovy script fails to read filesystem


The following groovy script works in the jenkins script console on the controller. However, it fails if I change the path to /path/to/workspace/prod_file.json and run the script on an agent node.

prod_file.json is pulled from github, otherwise they're the same. prod_file.json gets its trailing newline stripped, but even when that char is restored, the script fails. The permissions are the least restrictive (777). I even tried reading the file in python, and dumping it back to the fs as a new json file. I tried reading the file from /tmp, $HOME, $WORKSPACE, $WORKSPACE/other_project, etc.

I also tried the dot delimited path in add, e.g., add(it.jenkins_name)

The plugin provides no feedback, so I'm not sure where else to turn.

Is this a configuration issue, i.e., permissions, a file format issue, a bug in the plugin?

import groovy.json.JsonSlurper

def list = []
File textfile = new File('/tmp/test.json') 
JsonSlurper slurper = new JsonSlurper()
def parsedJson = slurper.parse(textfile)
parsedJson.each{ list.add(it['jenkins_name']) }
return list

Solution

  • Active Choices groovy script always runs on the controller node. Simple test:

    def host = 'hostname'.execute().text
    return [host]