Create Jenkins Pipeline – Chapter 4

The last chapter – Chapter 3 introduced the concept of Jenkins Pipeline and the steps to install Pipeline plugin in Jenkins. In this chapter, we will look into steps to create a simple pipeline project in Jenkins.

Step 1 -> Log into Jenkins and click on the ‘New Item’ option to create a pipeline project. Enter details as shown in snapshot below…

Step 2 -> When you click on ‘Pipeline’ you get 2 options – ‘Pipeline script’ (for scripted pipelines) and ‘Pipeline script from SCM’ (for declarative pipeline). Select the option you would like to implement, in our example – we will select ‘Pipeline script’ option.

Step 3 -> Start writing the code – a sample shown below. Post that, save it.

Step 4 -> Now to build the script, click on ‘Build Now’ option on left panel. The build gets triggered and displays below result-

To view result, click on build number ‘#1’, and then click on ‘Console Output’.

You will be able to view the text that you had scripted. Lets spend some time to understand the key segments in the pipeline-

a. Everything is wrapped in a ‘pipeline’

b. Inside a pipeline, we have ‘agent’ – in this example, we said that the activity will run on Jenkins Master

c. On the mentioned ‘agent’, the stages and related steps are mentioned.

We did talk about these elements in our last chapter, lets try to map it with our sample code-

This is just an example to test the pipeline and see how it works. In the next Chapter, we will focus on various options available to leverage pipeline feature as well as share some examples.

Happy Learning!!

Click here for Chapter 5 – Calling multiple jobs in Jenkins.