Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atulkamble/jenkins-java-maven-pipeline
This project provides a comprehensive guide for setting up a Jenkins pipeline to automate the build, test, and deployment processes of a basic Java Maven application. It includes sample Java code, Maven configuration (pom.xml), and a Jenkinsfile to facilitate continuous integration and deployment.
https://github.com/atulkamble/jenkins-java-maven-pipeline
cicd continuous-delivery continuous-deployment continuous-integration java jenkins maven pipeline
Last synced: about 5 hours ago
JSON representation
This project provides a comprehensive guide for setting up a Jenkins pipeline to automate the build, test, and deployment processes of a basic Java Maven application. It includes sample Java code, Maven configuration (pom.xml), and a Jenkinsfile to facilitate continuous integration and deployment.
- Host: GitHub
- URL: https://github.com/atulkamble/jenkins-java-maven-pipeline
- Owner: atulkamble
- Created: 2024-04-18T06:12:45.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-08-13T09:14:57.000Z (3 months ago)
- Last Synced: 2024-08-14T10:54:12.891Z (3 months ago)
- Topics: cicd, continuous-delivery, continuous-deployment, continuous-integration, java, jenkins, maven, pipeline
- Language: Shell
- Homepage: http://linkedin.com/in/atuljkamble
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Jenkins Pipeline Setup for Basic Java Maven Application
Comprehensive guide to set up a Jenkins pipeline for a basic Java Maven application, including the necessary Java code, `pom.xml`, `Jenkinsfile`, and steps to get everything up and running.
### 1. **Basic Java Code**
Create a simple Java project with the following file structure:
```
basic-java-app/
│
├── src/
│ └── main/
│ └── java/
│ └── com/
│ └── example/
│ └── App.java
│
├── pom.xml
└── Jenkinsfile
```#### `App.java`
```java
package com.example;public class App {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
```### 2. **Maven Configuration (`pom.xml`)**
Create a `pom.xml` file in the root directory of your project to define your Maven configuration:
```xml
4.0.0
com.example
basic-java-app
1.0-SNAPSHOT
jarBasic Java Application
A basic Java application with Maven
1.8
1.8
org.apache.maven.plugins
maven-compiler-plugin
3.8.1
1.8
1.8
```
### 3. **Jenkinsfile**
Create a `Jenkinsfile` in the root directory of your project to define the Jenkins pipeline:
```groovy
pipeline {
agent anytools {
maven 'Maven 3.8.6' // Ensure this version is configured in Jenkins
jdk 'JDK 11' // Ensure this JDK version is configured in Jenkins
}stages {
stage('Checkout') {
steps {
// Checkout code from SCM
checkout scm
}
}stage('Build') {
steps {
// Build the project using Maven
sh 'mvn clean install'
}
}stage('Test') {
steps {
// Run unit tests
sh 'mvn test'
}
}stage('Package') {
steps {
// Package the application
sh 'mvn package'
}
}stage('Deploy') {
steps {
// Simple deployment example
sh 'echo "Deploying application..."'
// Example of copying artifacts to a deploy location
sh 'cp target/basic-java-app-1.0-SNAPSHOT.jar /path/to/deploy/'
}
}
}post {
always {
// Clean up actions
sh 'echo "Cleaning up..."'
}success {
// Actions on successful build
echo 'Build succeeded!'
}failure {
// Actions on failed build
echo 'Build failed!'
}
}
}
```### 4. **Steps to Set Up and Run the Pipeline**
1. **Set Up Jenkins**:
- Install Jenkins and necessary plugins: `Git Plugin`, `Pipeline Plugin`, `Maven Integration Plugin`, and `JDK Tool`.2. **Configure Tools in Jenkins**:
- Go to `Manage Jenkins` > `Global Tool Configuration`.
- Add Maven and JDK installations that match the versions specified in the `Jenkinsfile`.3. **Create a New Jenkins Pipeline Job**:
- Open Jenkins and click on `New Item`.
- Choose `Pipeline`, enter a name for your job, and click `OK`.
- In the `Pipeline` section, select `Pipeline script from SCM`.
- Choose `Git` as the SCM and enter your repository URL.
- Set `Script Path` to `Jenkinsfile`.4. **Commit the Code to Your Repository**:
- Save the `App.java`, `pom.xml`, and `Jenkinsfile` in the root directory of your repository.
- Push the code to your Git repository.5. **Run the Pipeline**:
- Trigger a build in Jenkins to start the pipeline. Jenkins will checkout the code, build, test, package, and deploy your application according to the stages defined in the `Jenkinsfile`.### Customization
- **Deployment**: Customize the `Deploy` stage based on your actual deployment requirements.
- **Notifications**: Add additional steps in the `post` section for notifications or alerts.This setup will allow Jenkins to automate the build, test, and deployment processes for your basic Java Maven application. Adjust the `Jenkinsfile` and `pom.xml` as needed to fit your specific project requirements.