Published on: 12/28/20 11:56 AM
Category:DevOps Jenkins Tags: DevOps, Jenkins, jobIn last post, we have seen how to create simple job in Jenkins.
Now, in this post we will take a look on how can we create parameterized job in Jenkins.
Lets start with creating new project. Click on new item, and create freestyle project as below and hit OK button
From general setting, select checkbox – “This project is parameterized”
Now click on “Add Parameter” button
you can add parameter of type which ever you want , I am selecting string parameter for now.
Add some values to there, it is in combination of key value pair
so in above example, “Name” will be the key and default value will be “ZenConix”, this value can be change later. Description is optional here.
Now scroll down , into build section, select “Execute Windows batch command”
For test purpose, we are going to print back the value of our string parameter.
if you are on windows, then to get the value of parameter you need to write key in % example in our case it would be %name%
but if you are on mac or linux, then you need to write in with $ sign and in curly braces as ${name}
Now click on save job and our job is ready.
but if you observe this, this time we have “Build with Parameter” instead of just build option.
Click on “Build with parameters” and you can input the string parameter here
Click on build button to build this job.
Project build successfully, you can see history in Build history section
Click on #1 to see output of the project.
Inside console output, you can see our build statement as well as output of our windows batch command
we also can add more parameter here, to add more parameter, go to project and click on “configure”
Click on “Add parameter”, this time, we are going to add Boolean parameter
Added new parameter by name “TestCompleted” with default value as false as I have unchecked checkbox for default value
Click on Save and our configuration is ready. Now again click on “Build with parameters”. this time you can see new parameter which is boolean value as there is checkbox to check.