Scenario
You have been asked to set up a freestyle project that will contain two string parameters, your first and last names, and a build step executing a bash script that will display the greeting Hello followed by your full name.
Aim
To set up parameterized projects and access parameters
Prerequisites
Ensure the following:
- Jenkins is up and running
- You are logged in as the Administrator
Steps for Completion
- On the Jenkins dashboard, go to the configuration panel and select New Item.
- On the New Item view, enter a project name, select Freestyle project, then select OK.
- Under the general section of the project configuration, enter an appropriate project description.
- Enable the checkbox This project is parameterized to allow you to add parameters to the project, as shown in the following screenshot:
- Add the first parameter by clicking on the Add Parameter drop-down menu and selecting String Parameter, as shown in the following screenshot:
- Fill in the form with the details of the first parameter, that is, your first name, as displayed. This will present us with the form shown in the following screenshot:
- Follow the same procedure to create the second parameter for your last name. The final configuration should look like the following screenshot:
Our project now has two string parameters containing our first and last names. We can now proceed to add the build parameter to display the desired result.
- In the build section of the project configuration, select the Add build step drop-down menu and select Execute shell, as shown in the following screenshot:
- This presents us with a form requiring us to insert the command we want to execute. Populate the text area as shown in the following screenshot:
- Press Apply and Save at the bottom of the screen to save your project configuration. This will direct you to the project dashboard.
- On the left-hand project options menu, select Build with parameters to build the project:
- Fill in the parameters if you are not comfortable with running the project with the default parameters. Select Build.
- On the build history on the left, hover over the build number and select Console Output, as shown in the following screenshot:
From the Console Output, we can see that the build successfully displayed our first and last name, with the greeting as displayed on the following screenshot: