https://github.com/kausalyanp/sample-maven-project
Sample Freesyle with Maven Project using Jenkins, Maven 3.6.3, Java in Ubuntu server
https://github.com/kausalyanp/sample-maven-project
aws cicd devops ec2-instance freestyle java jdk jenkins maven maven-plugin pom ubunutu
Last synced: 3 months ago
JSON representation
Sample Freesyle with Maven Project using Jenkins, Maven 3.6.3, Java in Ubuntu server
- Host: GitHub
- URL: https://github.com/kausalyanp/sample-maven-project
- Owner: kausalyanp
- Created: 2024-11-13T12:45:20.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-14T06:13:50.000Z (over 1 year ago)
- Last Synced: 2025-10-29T00:35:12.154Z (8 months ago)
- Topics: aws, cicd, devops, ec2-instance, freestyle, java, jdk, jenkins, maven, maven-plugin, pom, ubunutu
- Language: Java
- Homepage:
- Size: 26.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sample-maven-project
Step 1: Install Jenkins
```
#!/bin/bash
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt install fontconfig openjdk-17-jre -y
sudo apt update
sudo apt-get install jenkins -y
```
Go to the Jenkins download page.
Choose your operating system and follow the specific installation steps.
Start Jenkins:
After installation, start Jenkins:
Linux: Run
```
sudo systemctl start jenkins.
```
Windows: Jenkins will typically run as a Windows service after installation.
Access Jenkins:
Open a web browser and go to http://localhost:8080.
Enter the initial admin password, which is found in the Jenkins installation directory, to complete the setup.
Step 2: Install Maven
Download Maven:
```
apt install maven
```
Download the latest version of Maven and follow the instructions to install it on your system.
Verify Installation:
Open a terminal (or command prompt) and type:
```
mvn -version
```
This should display the Maven version, Java version, and other environment information.
Step 3: Configure Jenkins for Maven
Open Jenkins and Configure Tools:
Go to Manage Jenkins > Global Tool Configuration.
Add Maven:
Scroll to the Maven section.
Click Add Maven and set a name (e.g., Maven3.6).
If Maven is not installed on the Jenkins server, you can check the option Install automatically to let Jenkins manage it.
Add Java (if not already configured):
Scroll to the JDK section and configure the Java Development Kit (JDK) similarly.
Step 4: Set Up a Sample Maven Project
To create a simple Maven project, you need to initialize a Maven project structure and configure necessary files:
Create Project Directory:
Open a terminal and create a new directory:
```
mkdir sample-maven-project
cd sample-maven-project
```
Initialize Maven Project:
Run the following command to create a basic Maven project structure:
```
mvn archetype:generate -DgroupId=com.example -DartifactId=sample-maven-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
This command will create the necessary files and folders, including pom.xml (Maven configuration file) and basic Java source files.
```
File Structure:
After running the above command, the file structure should look like this:
```
sample-maven-project
├── pom.xml
└── src
├── main
│ └── java
│ └── com
│ └── example
│ └── App.java
└── test
└── java
└── com
└── example
└── AppTest.java
```
Edit App.java (optional):
Open App.java in a text editor and add a simple main method if it doesn’t have one:
```
package com.example;
public class App {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
```
Edit AppTest.java (optional):
Make sure AppTest.java includes a simple test:
```
package com.example;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class AppTest {
@Test
public void shouldAnswerWithTrue() {
assertTrue(true);
}
}
```
Step 5: Upload Project to GitHub
Initialize Git:
```
git init
git add .
git commit -m "Initial commit"
```
Create a GitHub Repository:
Go to GitHub, create a new repository, and follow the instructions to push your code:
```
git remote add origin https://github.com/your-username/sample-maven-project.git
git push -u origin main
```
Step 6: Create a Freestyle Project in Jenkins
Create a New Project:
In Jenkins, click New Item.
Enter a name for your project (e.g., SampleMavenProject).
Select Freestyle project and click OK.
Configure Source Code Management:
In the project configuration page, scroll to Source Code Management and select Git.
Enter the GitHub repository URL.
Add credentials if required (such as a GitHub token).
Step 7: Configure Build with Maven
Add a Build Step:
Scroll down to the Build section and click Add Build Step.
Select Invoke Top-Level Maven Targets.
For Goals, enter clean install (this will clean and compile your project).
Specify the POM File:
Sample pom.xml file
```
4.0.0
com.example
sample-maven-project
1.0-SNAPSHOT
jar
1.8
1.8
UTF-8
junit
junit
4.13.1
test
org.apache.maven.plugins
maven-compiler-plugin
3.8.1
${maven.compiler.source}
${maven.compiler.target}
org.apache.maven.plugins
maven-surefire-plugin
2.22.2
```
If your pom.xml file is in the root directory, leave this field blank. If it's in a subdirectory, specify the path (e.g., /var/lib/jenkins/workspace/Project-1/sample-maven-project/pom.xml/pom.xml).
Step 8: Save and Build the Project
Save the Configuration:
Click Save to save the project configuration.
Step 9: Run the Build:
On the project page, click Build Now.
View the Console Output:
Go to Build History on the left panel, select the build, and click Console Output to view detailed logs of the build process.
Notes:
1. Use Ubuntu server version Ubuntu Server 22.04 LTS (HVM),EBS General Purpose (SSD)
2. Storage is 20 GiB (minimum required)
3. Allow "All TCP" traffic in security group inbound rule.
>>Created By Kausalya N P