View Code? Open in Web Editor
NEW
This project forked from wololock /jenkine-pipeline-maven-demo
Dockerfile 5.19%
Groovy 71.22%
Java 23.59%
jenkine-pipeline-maven-demo's Introduction
Jenkins Pipeline Maven build demo
Ex 1: Using Global Tools Configuration
#! groovy
pipeline {
agent any
tools {
maven " 3.6.0" // You need to add a maven with name "3.6.0" in the Global Tools Configuration page
}
stages {
stage(" Build" ) {
steps {
sh " mvn -version"
sh " mvn clean install"
}
}
}
post {
always {
cleanWs()
}
}
}
Ex 2: Using docker
agent and official Maven docker image
#! groovy
pipeline {
environment {
JAVA_TOOL_OPTIONS = " -Duser.home=/var/maven"
}
agent {
docker {
image " maven:3.6.0-jdk-13"
label " docker"
args " -v /tmp/maven:/var/maven/.m2 -e MAVEN_CONFIG=/var/maven/.m2"
}
}
stages {
stage(" Build" ) {
steps {
sh " mvn -version"
sh " mvn clean install"
}
}
}
post {
always {
cleanWs()
}
}
}
Ex 2: Using dockerfile
agent and Maven docker image build from the official image
#! groovy
pipeline {
environment {
JAVA_TOOL_OPTIONS = " -Duser.home=/home/jenkins"
}
agent {
dockerfile {
label " docker"
args " -v /tmp/maven:/home/jenkins/.m2 -e MAVEN_CONFIG=/home/jenkins/.m2"
}
}
stages {
stage(" Build" ) {
steps {
sh " ssh -V"
sh " mvn -version"
sh " mvn clean install"
}
}
}
post {
always {
cleanWs()
}
}
}
jenkine-pipeline-maven-demo's People