Jenkins – How to access parameters in a Parameterized Build

groovyJenkinsjenkins-pipeline

How do you access parameters set in the "This build is parameterized" section of a "Workflow" Jenkins job?

TEST CASE

  1. Create a WORKFLOW job.
  2. Enable "This build is parameterized".
  3. Add a STRING PARAMETER foo with default value bar text.
  4. Add the code below to Workflow Script:

    node()
    {
         print "DEBUG: parameter foo = ${env.foo}"
    }
    
  5. Run job.

RESULT

DEBUG: parameter foo = null

Best Answer

I think the variable is available directly, rather than through env, when using Workflow plugin. Try:

node()
{
    print "DEBUG: parameter foo = ${foo}"
}