Vizionz Vizionz - 2 months ago 28
Groovy Question

Jenkins Workflow - How to access parameters in a Parameterized Build?

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

Answer

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

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