Jenkins: Automating your delivery pipeline
Tags: java, spring, jenkins, devops
Published: 2020-12-28 22:11:23

In this post, we are going to create a Jenkins pipeline for a Java Spring project using Maven and Git:

#Accessing Jenkins dashboard and configuring Maven in Jenkins:

Click on "Manage Jenkins" and then in "Global Tool Configuration"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/s8sgsyxjmba2bb4i9vdu.png)

Add a Maven installation and provide a name for it. Click on Save.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/yy5ukhxl4o25anybpbzk.png)

#Creation of our first build job in Jenkins for a Spring application:

Click on "New Item"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7l1ifhb259btttqvos2c.png)

Provide a name for the project and choose "Freestyle Project"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fqp9qq348461ee2gt5fx.png)

Go to "Source Code Management", choose "Git", and provide the Repository URL and the branch.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/164oywc9305altdu637u.png)

Go to the "Build" tab and choose "Invoke top-level Maven targets"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1gcdbj2mf0k2no1bd7d7.png)

Choose the Maven Version, write compile in the goals and click on "Save"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/62g8olc1volpioiaaxjl.png)

Click on "Build Now"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/z7848jfwsxe73i0gbp7w.png)

Click on "Console Output" in the first build of the Build History section
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7i3x6ni6mjyvwf1k4i59.png)

Confirm the "SUCCESS" message is displayed when finished
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/60god1mxu4167ricv5sq.png)

#Developing and viewing of a delivery pipeline of a Spring  application with two stages build and test in Jenkins

Let's create a New Item
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/dyviseds3uyd4szfoht2.png)

Enter an item name, choose the "Freestyle project" and click OK
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/x39aqy7j07ae9ruwagzo.png)

Go to the "Source Code Management" tab, select "Git", provide the URL of the Repository, and the branch
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/m54gjxhu1ctqu8mplo0z.png)

Go to the "Build" tab and choose "Invoke top-level Maven targets"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1gcdbj2mf0k2no1bd7d7.png)

Choose the Maven Version, write test in the goals and click on "Save"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/w650pe8nb9n29iwlyssd.png)

Click on "Build Now"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2346l9iu0qmh6oyilap0.png)

Click on "Console Output" in the first build of the Build History section
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hqd0l3zai3h91ii1smu4.png)

Confirm the "SUCCESS" message is displayed when finished
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3ukil8gfkcs258tucvm5.png)

To do it automatically after the compile job, let's go to the "Configure" option of the item
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/nq7eghv1vwthuum5uiqe.png)

Go to the "Build Triggers" section and select the "Build after other projects are built" option. Then, enter the other project name, and click "Save"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/55l51c6v2g8xif6c0xzs.png)

Go to the "Manage Jenkins" option in the main menu and choose "Manage Plugins"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pn40g5x54xzpoquoswxf.png)

Go to the "Available" tab and look for "Build pipeline". Choose it and click on "Install without Restart"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rsfmue5s4lzmmm7dk0nb.png)

Choose the plus symbol in the main dashboard
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zibqadjreksd11tjz1u4.png)

Choose the "Build Pipeline View" option, provide a view name, and click on "OK"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xf66km2r9ulriw8hvbcg.png)

Select the initial job and click ok
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/az99750zi0utkpnc0k61.png)

Click "Run"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wwo6w4tc7h53yy06smlv.png)

#Transforming your delivery pipeline in the form of scripted/declarative pipeline

First, install the "Pipeline Maven Integration Plugin"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qh606q3i8e72c6kk21f1.png)

Now, let's create a new item (Pipeline)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5jkgluv98f0dbblbt5dy.png)

Then, go to the "Pipeline" tab and choose "Scripted Pipeline" or "GitHub + Maven" for a declarative pipeline
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/37oveg05mzfeb60h1sc3.png)

Finally, adapt the code according to your needs, and click on "Save"
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/bqk0jlmxdzqrxc2v80bo.png)

If you click on "Build Now" you can see the result
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/y5xwu309iz681146q3bh.png)

#Developing a Jenkinsfile for our application
If you chose "GitHub + Maven" for a declarative pipeline you can copy that code into a Jenkinsfile in the root of your project. Now, edit the Pipeline and select "Pipeline script from SCM". Then, choose Git as your SCM and provide the Repository URL and branch. Finally, click "Save" and "Build now" to test your pipeline
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1nuustbgwtek68hk6rzz.png)