Maven is a build automation tool primarily used for java projects.In software development,"Build" is a process of creating a final application in the form of executables or binaries by combining and compiling all the required source code.Build process for a simple peice of code like a "hello world!" would not be complicated but in the case of huge projects there might be several dependencies and plugins required to make an executable.In such cases , a set of instructions to add the plugins and dependencies required must be given during build automation. Maven takes this information from pom.xml file. Therefore to use maven for build automation pom.xml file is required.
- Install JDK (if you haven't)
- Install Maven:
- on ubuntu :
sudo apt-get install maven - on mac: usually comes with java
- on ubuntu :
- Get Maven & Java home locations:
- run
mvn -v | awk 'FNR==2 {print $3}'to get maven home directory - run
mvn -v | awk 'FNR==4 {print substr($3,1,34)}'to get java jdk location
- run
- Login to jenkins and in the Jenkins Dashboard:
- manage Jenkins > Global Tool Configuation
- click on "JDK installations"
- enter name(example:jdk) and JAVA_HOME(from step 3)
- click on "MAVEN installations"
- enter name(example:maven) and MAVEN_HOME(from step 3)
- click on apply and save
- Get back to jenkins default dashboard
- click on "New Item"
- enter a name for the project
- choose "Freestyle project" as project type
- click "ok"
- Configure the project:
- in Source code management, choose git
- enter the path any java project with a pom.xml file. For understanding purposes, refer to Pom.xml Reference
- in Build, click on advanced
- choose the maven version configured in step 4
- give the path to Pom.xml file
- enter Goals (for ex: clean install)
- click apply and save
- Cick on "build now"
- After build completes, look at the console output. We can see "build success"
- We can find the packaged files in the workspace directory of the job, in 'target' folder
References: