Outline
- Creating the Build
- Maven Project Name and Description
- Discarding Old Builds
- Source Code Management
- Build Triggers
- Root POM
- Running the Build
- Troubleshooting
- Local JAR Installations
Environment Assumptions
- Jenkins 1.595
- Ubuntu 14.04
- Apache Maven 3.2.3
- Git 1.9.5
- Oracle JDK 7
Creating a Maven Build Project
Let's tell Jenkins to create a new item.
I'll open my web browser to
http://localhost:8080
and click on new item:
I'm going to name the maven project using the artifactId from my POM file. This is convention; not a Jenkins requirement:
Scroll down a little further, and enter the
- Maven Project Name
- Description
- Github Project URL
- and optionally, select an option for Discarding Old Builds
Discarding Old Builds
It's best to have a strategy for discarding old builds. The server host can quickly run out of disk space if old builds are retained indefinitely.
Jenkins will permit configuration for "Days to keep builds" and "Max # of builds to keep. I generally keep the last 5 builds:
Source Code Management
Select "Git" and supply the same URL you use to clone your repository in the "Repository URL" section. Credentials will be either added to the global repository for the first time, or selected from pre-existing credentials:Building Triggers
Jenkins comes with five options for build triggers.
1. Build whenever a SNAPSHOT dependency is built
I leave this checked as default, but don't overly rely on it.
2. Build after other projects are built
I have a series of projects that are interconnected. When one of them is built in Jenkins, this will trigger downstream (dependent) projects to be built as well. I find it useful to schedule a CRON job (see next section) on the base project, and let the downstream triggered using this option.
This option likewise gives me the option to assess the stability of an upstream build, prior to initiating this trigger.
In this case, I choose to move forward with the build, even if the "trend" of the build is unstable.
3. Building Periodically
Jenkins uses CRON expressions as a schedule to execute some routine. A CRON expression is a string comprising five or six fields separated by white space.
I'm currently scheduling by builds to run every 10 minutes by including this expression:
H/10 * * * *
The Maven configuration section looks like this:
4. Build when a change is pushed to GitHub
This is another useful trigger (additional configuration required).
5. Poll SCM
Similar to the fourth option. I'm not sure if there's any benefit to configuring both of these simultaneously.
Quick References:
- [Stackoverflow] Using Snapshot Dependencies
- [Stackoverflow] How to schedule jobs in Jenkins
- Trigger Builds when Changes are Pushed to Github
The Root POM
It's not unlikely that your Git repository will have multiple Java projects. In this case, you will want to have a parent POM file that can control the build for the entire workspace.
This is the POM that you pass off to Jenkins here:
Building the Project
At this point, configuration is complete, and you can click the Save button.
On the Jenkins dashboard, select "Build Now" to validate that your project can be built correctly:
The progress of this task can be tracked by clicking on the build work item that shows up in the Build History box.
This will take you to a page that will give you both real-time and (eventually) historical progress of this build:
Clicking on Console Output will give you the Maven console output from this build.
Local JAR Installations
Do any of your Maven POM reference JAR files that are installed locally? You will need to install these on your Jenkins server prior to a successful build.
I have had some trouble getting this to work, and it would appear that I am not alone:
- Jenkins Bug Report [10123]
- No formal fix provided; some users report success and are unable to replicate the issue.
- [Stackoverflow] How to manage third-party dependency with Eclipse, Maven and Jenkins?
- A primary suggestion is to go with a third-party repository (like Sonatype Nexus).
I am using a workaround at the moment:
<dependency>
<groupId>jaws</groupId>
<artifactId>jaws</artifactId>
<version>1.2</version>
<type>jar</type>
<scope>system</scope>
<systemPath>/home/craig/jaws-bin.jar</systemPath>
</dependency>
This will get Jenkins to work, but it's not a recommended approach.
Thanks for such a clear explanation. Very good blog post on Maven. This is so useful for DevOps candidates.
ReplyDeleteBest Regards,
DevOps Training in Hyderabad
DevOps Online Training in Hyderabad
DevOps Online Training
DevOps Institutes in Hyderabad
Learn DevOps Online
Best DevOps Training Institute in Hyderabad
Best DevOps Online Training Institute in Hyderabad
Best DevOps Online Training in India
DevOps Institute in Hyderabad
Best DevOps Training
DevOps Training and Certification
learn DevOps
DevOps Institutes in Ameerpet
DevOps Training
DevOps Courses
DevOps Certification Training
CourseIng
Well written .Keep sharing Devops Online Course
ReplyDeleteThank you for sharing the article. The data that you provided in the blog is informative and effective. Best Devops Training Institute
ReplyDeleteReally very happy to say that your post is very interesting. I never stop myself to say something about it. You did a great job. Keep it up.
ReplyDeleteWe have an excellent IT courses training institute in Hyderabad. We are offering a number of courses that are very trendy in the IT industry. For further information, please once go through our site.
DevOps Training In Hyderabad
Thanks for the informative article.
ReplyDeleteDevOps Online Training in Hyderabad
DevOps Training Online
DevOps Training institute in Ameerpet
Very interesting blog I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well.
ReplyDeleteSalesforce Training in Chennai
Salesforce Online Training in Chennai
Salesforce Training in Bangalore
Salesforce Training in Hyderabad
Salesforce training in ameerpet
Salesforce Training in Pune
Salesforce Online Training
Salesforce Training
ReplyDeleteVery Nice Blog…Thanks for sharing this information with us. Here am sharing some information about training institute.
tableau training in hyderabad
Thanks for sharing such a wonderful blog.
ReplyDeleteDevOps classes in Pune