Section10 Jenkins&Maven
Section10 Jenkins&Maven
What is Maven?
• Maven is a build automation tool for Java projects.
• Helps in compiling, testing, packaging, and managing dependencies of Java applications.
• Simplifies project management with a standardized project structure.
Key Takeaways:
• The Maven Integration Plugin allows Jenkins to work with Maven-based projects.
• Installation is done via Manage Plugins in Jenkins.
• Restarting Jenkins after installation ensures the plugin is loaded correctly.
• Validation can be done by checking the Installed Plugins tab.
3. Installing the Git Plugin in Jenkins
Objective:
• Learn how to install the Git plugin in Jenkins to enable Git integration for source code
management.
Key Takeaways:
• The Git Plugin is required for integrating Git repositories with Jenkins.
• Installation follows the same process as other Jenkins plugins.
• Restarting Jenkins ensures the plugin loads correctly.
• Verification is done via the Installed Plugins tab in Jenkins.
5. Verify that the cloned repository matches the original GitHub repo structure.
Key Takeaways:
✅ SCM (Source Code Management) helps Jenkins fetch the latest code from repositories.
✅ Jenkins stores project files in a workspace specific to each job.
✅ The Git plugin allows seamless integration with GitHub/GitLab.
✅ Users can manually verify cloned files within the Jenkins workspace directory.
4. You should see the JAR file generated in the target/ directory.
5. Key Takeaways
✅ Maven Integration → Configured in Jenkins under Global Tool Configuration.
✅ Maven Job → Defined in Jenkins to automatically fetch and build the latest code.
✅ Artifacts → The resulting JAR file is stored in the target/ directory in the workspace.
✅ Continuous Integration (CI) Flow:
• Pull latest code
• Build the JAR
• Store it in the workspace
Solution:
1. Go to Jenkins Dashboard → Click Manage Jenkins.
2. Click Configure System.
3. Find Global Environment Variables → Click Add.
4. Enter:
• Name: JAVA_TOOL_OPTIONS
• Value: -Djava.awt.headless=true
5. Click Save.
5. Re-run the Build to Validate Fix
Steps to Verify Fix:
1. Click Build Now again.
2. Check the Console Output.
3. You should see:
Tests run: 2, Failures: 0
6. Key Takeaways
✅ Unit Testing Integrated → Maven test command is added to Jenkins job.
✅ Error Handling → Fixed environment variable issue for Debian-based systems.
✅ CI Workflow Extended → Now includes code validation through unit tests.
This is the core of Continuous Integration (CI) – ensuring the latest code is compiled, packaged,
and validated automatically. 🚀
6. Click Save.
• If your JAR contains a simple application that prints "Hello, World!", you should see
this message.
• This confirms that the JAR is executing correctly.
6. Key Takeaways
✅ Automated Deployment → Jenkins now builds and runs your JAR.
✅ Error Prevention → JAR is deployed only if all tests pass.
✅ Verifying Deployment → Output confirms JAR execution inside Jenkins.
6. Click Save.
5. Key Takeaways
✅ JUnit Reports are stored in target/surefire-reports/.
✅ Jenkins can visualize test trends using XML reports.
✅ Running the job multiple times generates a meaningful graph.
5. Key Takeaways
✅ Artifacts are build outputs like JARs.
✅ Jenkins can automatically archive successful builds.
✅ You can easily download the last successful artifact.
4. Key Takeaways
✅ Jenkins can send automatic email alerts for builds.
✅ Failure notifications help developers fix issues faster.
✅ Success notifications confirm when a build is back to normal.