Reputation: 140
In my jenkinsfile, I have following params and would like to create a env variable that sums up these two params. How to do this?
parameters {
string(name: 'log_act_instances', defaultValue: '1')
string(name: 'log_arb_instances', defaultValue: '1')
}
environment {
log_instances = log_act_instances+log_arb_instances (Value should be 2 for log_instances)
}
Upvotes: 2
Views: 3060
Reputation: 28739
You can access the parameters from within the params
map. You also need to convert the parameters to integers, because currently the +
operator would return 11
and not 2
because they are both strings.
From within the env
block, a parameter would be accessed and could be converted to an integer like:
params.log_act_instances.toInteger()
The full code would appear like:
environment {
log_instances = "${params.log_act_instances.toInteger() + params.log_arb_instances.toInteger()}"
}
Upvotes: 3