0% found this document useful (0 votes)
6 views5 pages

Jenkins Maven Build Pipeline Setup

Uploaded by

24202014
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Jenkins Maven Build Pipeline Setup

Uploaded by

24202014
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROGRAM 4:

Aim: To create maven build pipeline using Jenkins.

Algorithm:

1. Ensure Maven is Installed:

o Verify that Maven is installed on your system by running mvn -v in your terminal or
command prompt.

o If Maven is not installed, download and install it from the Maven website.

2. Set Up the Project Directory:

o Create a new directory for your project.

o Inside this directory, create the necessary subdirectories: src/main/java and


src/main/resources.

3. Add Your Source Files:

o Place [Link] and [Link] inside the src/main/java directory.

4. Add Your [Link] File:

o Place the provided [Link] file in the root of your project directory.

Project Directory Structure

your-project-directory/

|-- [Link]

|-- src/

|-- main/

|-- java/

|-- [Link]

|-- [Link]

5. Run Maven Commands:

o Open a terminal or command prompt and navigate to your project directory.

o Execute the following Maven commands:

Maven Commands

# Navigate to the project directory

cd path/to/your-project-directory

# Clean the project (optional but recommended to ensure a fresh build)

mvn clean

# Compile the project


mvn compile

# Package the project into a JAR file

mvn package

1. Install Jenkins and Necessary Plugins

● Install Jenkins:

o Download and install Jenkins from the official Jenkins website.

● Install Plugins:

o Go to Manage Jenkins -> Manage Plugins.

o Install the following plugins:

▪ Maven Integration Plugin

▪ Git Plugin (if you are using a Git repository)

2. Set Up Maven in Jenkins

● Go to Manage Jenkins -> Global Tool Configuration.

● Add a Maven installation:

o Click on Add Maven.

o Provide a name (e.g., Maven 3.8.1).

o Set the Install automatically option, or provide the path to the local Maven
installation.

3. Create a New Maven Project

● Go to the Jenkins dashboard.

● Click on New Item.

● Enter a name for the job (e.g., Helloworld Maven Build).

● Select Maven project and click OK.

4. Configure the Maven Project

1. Source Code Management:

o In the Source Code Management section, select Git.

o Enter the repository URL (e.g., [Link]

2. Build Environment:
o You can configure additional build environment settings as needed (e.g., clean
workspace before build).

3. Build:

o In the Build section, click Add build step and select Invoke top-level Maven targets.

o Configure the Maven build step:

▪ Maven Version: Select the Maven installation you configured earlier.

▪ Goals: Enter clean install.

▪ POM: Leave this blank if your [Link] is in the root directory of your
repository, or specify the relative path if it is located elsewhere.

▪ Save and click build now and download the zip file.

Code:

[Link]

public class Helloworld {

public static void main(String[] args) {

Greeter greeter = new Greeter();

[Link]();

[Link]

public class Greeter {

public Greeter() {

// Constructor code here

public void greet() {

[Link]("Hello, world!");

[Link]

<?xml version="1.0" encoding="UTF-8"?>


<project xmlns="[Link]
xmlns:xsi="[Link]

xsi:schemaLocation="[Link] [Link]
v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>[Link]</groupId>

<artifactId>jb-hello-world-maven</artifactId>

<packaging>jar</packaging>

<version>0.1.0</version>

<build>

<plugins>

<plugin>

<groupId>[Link]</groupId>

<artifactId>maven-shade-plugin</artifactId>

<version>2.1</version>

<executions>

<execution>

<phase>package</phase>

<goals>

<goal>shade</goal>

</goals>

<configuration>

<transformers>

<transformer

implementation="[Link]">

<mainClass>Helloworld</mainClass>

</transformer>

</transformers>

</configuration>

</execution>
</executions>

</plugin>

</plugins>

</build>

</project>

Output:

You might also like