java-tutorials/spring-jenkins-pipeline/scripted-pipeline-unix-nonunix

71 lines
2.7 KiB
Plaintext
Raw Normal View History

node {
stage 'Clone the project'
git 'https://github.com/dassiorleando/tutorials.git'
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',
canRunOnFailed: true,
defaultEncoding: '',
healthy: '100',
2017-12-14 15:24:31 -05:00
pattern: '**/target/checkstyle-result.xml',
unHealthy: '90',
useStableBuildAsReference: true
])
}
}
}
stage("Tests and Deployment") {
parallel 'Unit tests': {
stage("Runing unit tests") {
if (isUnix()) {
sh "./mvnw test -Punit"
} else {
bat "./mvnw.cmd test -Punit"
}
2017-12-14 15:24:31 -05:00
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*UnitTest.xml'])
}
}, 'Integration tests': {
stage("Runing integration tests") {
if (isUnix()) {
sh "./mvnw test -Pintegration"
} else {
bat "./mvnw.cmd test -Pintegration"
}
2017-12-14 15:24:31 -05:00
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*IntegrationTest.xml'])
}
}, 'Deployment': {
stage("Staging") {
if (isUnix()) {
sh "pid=\$(lsof -i:8989 -t); kill -TERM \$pid || kill -KILL \$pid"
} else {
2017-12-14 15:24:31 -05:00
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']) {
if (isUnix()) {
sh 'nohup ./mvnw spring-boot:run -Dserver.port=8989 &'
} else {
bat 'start ./mvnw.cmd spring-boot:run -Dserver.port=8989'
}
}
}
}
}
}
}