I am adding jenkins parameters to a job from system groovy script (one build step):
1-st step.
import hudson.model.*
def pa = new ParametersAction([
new StringParameterValue("firstParam", 1), new StringParameterValue("secondParam", 2)
])
Thread.currentThread().executable.addAction(pa)
Now when I try to execute the next system groovy build step, I am looking for them and they are not there:
2nd step.
def firstParam = "firstParam"
def secondParam = "secondParam"
def resolver = build.buildVariableResolver
def firstParamValue = resolver.resolve(firstParam)
def secondParamValue = resolver.resolve(secondParam)
println firstParamValue
println secondParamValue
they both print null! How do I get the parameters in the next system groovy build step?
The weird thing is that when I try a shell execution as a following step and if I do:
echo $firstParam
echo $secondParam
I get both 1 and 2 printed.
Even when I try to print all parameters with the below code I don't get them:
def thr = Thread.currentThread()
def build = thr?.executable
def parameters = build?.actions.find{ it instanceof ParametersAction }?.parameters
parameters.each {
println "parameter ${it.name}:"
println it.dump()
println "-" * 80
}