2017-12-04 23:29:10 -05:00
|
|
|
node {
|
|
|
|
stage 'Clone the project'
|
2017-12-16 10:46:57 -05:00
|
|
|
git 'https://github.com/eugenp/tutorials.git'
|
2017-12-04 23:29:10 -05:00
|
|
|
|
|
|
|
dir('spring-jenkins-pipeline') {
|
|
|
|
stage("Compilation and Analysis") {
|
|
|
|
parallel 'Compilation': {
|
|
|
|
if (isUnix()) {
|
|
|
|
sh "./mvnw clean install -DskipTests"
|
|
|
|
} else {
|
|
|
|
bat "./mvnw.cmd clean install -DskipTests"
|
|
|
|
}
|
|
|
|
}, 'Static Analysis': {
|
|
|
|
stage("Checkstyle") {
|
|
|
|
if (isUnix()) {
|
|
|
|
sh "./mvnw checkstyle:checkstyle"
|
|
|
|
} else {
|
|
|
|
bat "./mvnw.cmd checkstyle:checkstyle"
|
2017-12-14 15:24:31 -05:00
|
|
|
}
|
|
|
|
step([$class: 'CheckStylePublisher',
|
2017-12-04 23:29:10 -05:00
|
|
|
canRunOnFailed: true,
|
|
|
|
defaultEncoding: '',
|
|
|
|
healthy: '100',
|
2017-12-14 15:24:31 -05:00
|
|
|
pattern: '**/target/checkstyle-result.xml',
|
2017-12-04 23:29:10 -05:00
|
|
|
unHealthy: '90',
|
|
|
|
useStableBuildAsReference: true
|
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage("Tests and Deployment") {
|
|
|
|
parallel 'Unit tests': {
|
2017-12-27 00:46:22 -05:00
|
|
|
stage("Running unit tests") {
|
|
|
|
try {
|
|
|
|
if (isUnix()) {
|
|
|
|
sh "./mvnw test -Punit"
|
|
|
|
} else {
|
|
|
|
bat "./mvnw.cmd test -Punit"
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*UnitTest.xml'])
|
|
|
|
throw err
|
2017-12-04 23:29:10 -05:00
|
|
|
}
|
2017-12-14 15:24:31 -05:00
|
|
|
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*UnitTest.xml'])
|
|
|
|
|
2017-12-04 23:29:10 -05:00
|
|
|
}
|
|
|
|
}, 'Integration tests': {
|
2017-12-27 00:46:22 -05:00
|
|
|
stage("Running integration tests") {
|
|
|
|
try {
|
|
|
|
if (isUnix()) {
|
|
|
|
sh "./mvnw test -Pintegration"
|
|
|
|
} else {
|
|
|
|
bat "./mvnw.cmd test -Pintegration"
|
|
|
|
}
|
|
|
|
} catch(err) {
|
|
|
|
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*IntegrationTest.xml'])
|
|
|
|
throw err
|
2017-12-04 23:29:10 -05:00
|
|
|
}
|
2017-12-14 15:24:31 -05:00
|
|
|
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*IntegrationTest.xml'])
|
2017-12-04 23:29:10 -05:00
|
|
|
}
|
2017-12-27 00:46:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
stage("Staging") {
|
|
|
|
if (isUnix()) {
|
|
|
|
sh "pid=\$(lsof -i:8989 -t); kill -TERM \$pid || kill -KILL \$pid"
|
|
|
|
} else {
|
|
|
|
bat "FOR /F \"tokens=5 delims= \" %%G IN (\"netstat -a | findstr :8989\") DO TaskKill.exe /PID %%G /fi \"memusage gt 0\""
|
|
|
|
}
|
|
|
|
|
|
|
|
withEnv(['JENKINS_NODE_COOKIE=dontkill']) {
|
2017-12-04 23:29:10 -05:00
|
|
|
if (isUnix()) {
|
2017-12-27 00:46:22 -05:00
|
|
|
sh 'nohup ./mvnw spring-boot:run -Dserver.port=8989 &'
|
2017-12-04 23:29:10 -05:00
|
|
|
} else {
|
2017-12-27 00:46:22 -05:00
|
|
|
bat 'start ./mvnw.cmd spring-boot:run -Dserver.port=8989'
|
2017-12-04 23:29:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|