Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all parameters(Parameterized build) from jenkins pipeline?

I am building one Parameterized pipeline job in newer version of jenkins.In older version of jenkins i have used getbinding().getVariables() to retrieve all parameters. But newer version it is return null values. How to retrieve parameters(all) in newer version of jenkins?

like image 776
Learner Avatar asked Jan 21 '19 06:01

Learner


People also ask

How do I get build parameters in Jenkins pipeline?

We will begin by creating a new job. Go to Jenkins Home, select New Item, add a name for your Job, for the project type, select Pipeline project and click on Ok. On the configure job page select the This project is parameterized checkbox in the general tab.

How do you use parameters in Jenkins pipeline script?

You just have to use params. [NAME] in places where you need to substitute the parameter. Here is an example of a stage that will be executed based on the condition that we get from the choice parameter. The parameter name is ENVIRONMENT , and we access it in the stage as params.

Which data structure is used to expose all parameters defined for the Jenkins pipeline?

params. Exposes all parameters defined for the Pipeline as a read-only Map, for example: params.


2 Answers

You can access parameters using "params" variable.

params.each {param ->
  println "${param.key} -> ${param.value} "
}
like image 157
Jayan Avatar answered Nov 12 '22 13:11

Jayan


For string parameters, call trim(). Modifying @Jayan's example:

params.each {param ->
  println " '${param.key.trim()}' -> '${param.value.trim()}' "
}
like image 21
shfnet Avatar answered Nov 12 '22 14:11

shfnet