How to access parameters in a Parameterized Build?

前端 未结 10 2049
你的背包
你的背包 2020-11-29 04:44

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

TEST CASE

相关标签:
10条回答
  • 2020-11-29 05:42

    As per Pipeline plugin tutorial:

    If you have configured your pipeline to accept parameters when it is built — Build with Parameters — they are accessible as Groovy variables of the same name.

    So try to access the variable directly, e.g.:

    node()
    {
         print "DEBUG: parameter foo = " + foo
         print "DEBUG: parameter bar = ${bar}"
    }
    
    0 讨论(0)
  • 2020-11-29 05:45

    Please note, the way that build parameters are accessed inside pipeline scripts (pipeline plugin) has changed. This approach:

    getBinding().hasVariable("MY_PARAM")
    

    Is not working anymore. Please try this instead:

    def myBool = env.getEnvironment().containsKey("MY_BOOL") ? Boolean.parseBoolean("$env.MY_BOOL") : false
    
    0 讨论(0)
  • 2020-11-29 05:46

    Use double quotes instead of single quotes

    e.g. echo "$foo" as opposed to echo '$foo'

    If you configured your pipeline to accept parameters using the Build with Parameters option, those parameters are accessible as Groovy variables of the same name. See Here.

    You can drop the semicolon (;), drop the parentheses (( and )), and use single quotes (') instead of double (") if you do not need to perform variable substitutions. See Here. This clued me into my problem, though I've found that only the double (") is required to make it work.

    0 讨论(0)
  • 2020-11-29 05:46

    The following snippet gives you access to all Job params

        def myparams = currentBuild.rawBuild.getAction(ParametersAction)
        for( p in myparams ) {
            pMap[p.name.toString()] = p.value.toString()
        }
    
    0 讨论(0)
提交回复
热议问题