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
Add a Maven installation and provide a name for it. Click on Save.
👁 Alt Text
Creation of our first build job in Jenkins for a Spring application:
Click on "New Item"
👁 Alt Text
Provide a name for the project and choose "Freestyle Project"
👁 Alt Text
Go to "Source Code Management", choose "Git", and provide the Repository URL and the branch.
👁 Alt Text
Go to the "Build" tab and choose "Invoke top-level Maven targets"
👁 Alt Text
Choose the Maven Version, write compile in the goals and click on "Save"
👁 Alt Text
Click on "Build Now"
👁 Alt Text
Click on "Console Output" in the first build of the Build History section
👁 Alt Text
Confirm the "SUCCESS" message is displayed when finished
👁 Alt Text
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
Enter an item name, choose the "Freestyle project" and click OK
👁 Alt Text
Go to the "Source Code Management" tab, select "Git", provide the URL of the Repository, and the branch
👁 Alt Text
Go to the "Build" tab and choose "Invoke top-level Maven targets"
👁 Alt Text
Choose the Maven Version, write test in the goals and click on "Save"
👁 Alt Text
Click on "Build Now"
👁 Alt Text
Click on "Console Output" in the first build of the Build History section
👁 Alt Text
Confirm the "SUCCESS" message is displayed when finished
👁 Alt Text
To do it automatically after the compile job, let's go to the "Configure" option of the item
👁 Alt Text
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
Go to the "Manage Jenkins" option in the main menu and choose "Manage Plugins"
👁 Alt Text
Go to the "Available" tab and look for "Build pipeline". Choose it and click on "Install without Restart"
👁 Alt Text
Choose the plus symbol in the main dashboard
👁 Alt Text
Choose the "Build Pipeline View" option, provide a view name, and click on "OK"
👁 Alt Text
Select the initial job and click ok
👁 Alt Text
Click "Run"
👁 Alt Text
Transforming your delivery pipeline in the form of scripted/declarative pipeline
First, install the "Pipeline Maven Integration Plugin"
👁 Alt Text
Now, let's create a new item (Pipeline)
👁 Alt Text
Then, go to the "Pipeline" tab and choose "Scripted Pipeline" or "GitHub + Maven" for a declarative pipeline
👁 Alt Text
Finally, adapt the code according to your needs, and click on "Save"
👁 Alt Text
If you click on "Build Now" you can see the result
👁 Alt Text
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
For further actions, you may consider blocking this person and/or reporting abuse
