Sunday, 1 November 2020

Creating Jenkins Pipeline for the Maven Build

Step1: New Job in Jenkins


Create a Job in Jenkins

Login into Jenkins and select the New item from the Dashboard.


Step2: Create a Pipeline

Name the Item as Maven-Pipeline and Select the Pipeline from the drop-down.

Select Ok.


Step3: Adding Pipeline Code

Select the pipeline tab and add the below entries.




pipeline {
environment {
registry = "syedghouse14/greet-user-repo"
registryCredential = 'Docker-Hub'
dockerImage = ''
dockerfile="${workspace}\\GreetUser\\Dockerfile"
pomfile="${workspace}\\GreetUser\\pom.xml"
}
agent any
stages {
stage('Cloning Git') {
steps {
git 'https://github.com/Syed-SearchEndeca/gretuser.git'
}
}
stage ('Build') {
steps {
withMaven(maven : 'apache-maven-3.6.3') {
bat "mvn clean package -f ${pomfile}"
}
}
}
}
}

then select Save.

Step4: Select Build Now.




Step5: Success




Things to understand here.

I don't have the pom file defined directly hence defining like the below.

steps {
withMaven(maven : 'apache-maven-3.6.3') {
bat "mvn clean package -f ${pomfile}"
}

Here 

pomfile="${workspace}\\GreetUser\\pom.xml"

Where else the ${workspace} is my Jenkins workspace pointing to 

"C:\Users\Syed\AppData\Local\Jenkins\.jenkins\workspace\GreetUser"

Happy Learning !!!

No comments:
Write comments