We’re using Jenkins version 1.651 with the Groovy plugin for Jenkins version 1.4.
I had real trouble getting access to the build parameters when trying to run a groovy script build step using the recommended methods of which there are many.
From the plugin documentation:
// Retrieve parameters of the current build def foo = build.buildVariableResolver.resolve("FOO") println "FOO=$foo"
This doesn’t work.
From Jenkins help:
def thr = Thread.currentThread() def build = thr.executable // get build parameters def buildVariablesMap = build.buildVariables // get all environment variables for the build def buildEnvVarsMap = build.envVars
String jobName = buildEnvVarsMap?.JOB_NAME
This also doesn’t work but I believe that’s because the groovy script isn’t running in the same process as the Jenkins job (or so I’ve heard).
I also tried the Jenkins wiki that suggested:
So, to the solution…
import hudson.model.* def foobar = System.getenv("FOOBAR")
It’s so simple it’s painful.