Jenkins pipeline script for unix and non-unix OS
This commit is contained in:
parent
6d36470a65
commit
c067162a56
|
@ -21,6 +21,7 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
|
<checkstyle.version>2.17</checkstyle.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -48,7 +49,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
<version>2.17</version>
|
<version>${checkstyle.version}</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
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"
|
||||||
|
|
||||||
|
step([$class: 'CheckStylePublisher',
|
||||||
|
canRunOnFailed: true,
|
||||||
|
defaultEncoding: '',
|
||||||
|
healthy: '100',
|
||||||
|
pattern: '**/target/checkstyle-result.xml',
|
||||||
|
unHealthy: '90',
|
||||||
|
useStableBuildAsReference: true
|
||||||
|
])
|
||||||
|
} else {
|
||||||
|
bat "./mvnw.cmd checkstyle:checkstyle"
|
||||||
|
|
||||||
|
step([$class: 'CheckStylePublisher',
|
||||||
|
canRunOnFailed: true,
|
||||||
|
defaultEncoding: '',
|
||||||
|
healthy: '100',
|
||||||
|
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"
|
||||||
|
|
||||||
|
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*UnitTest.xml'])
|
||||||
|
} else {
|
||||||
|
bat "./mvnw.cmd test -Punit"
|
||||||
|
|
||||||
|
step([$class: 'JUnitResultArchiver', testResults: '**\target\surefire-reports\TEST-*UnitTest.xml'])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 'Integration tests': {
|
||||||
|
stage("Runing integration tests") {
|
||||||
|
if (isUnix()) {
|
||||||
|
sh "./mvnw test -Pintegration"
|
||||||
|
|
||||||
|
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*IntegrationTest.xml'])
|
||||||
|
} else {
|
||||||
|
bat "./mvnw.cmd test -Pintegration"
|
||||||
|
|
||||||
|
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 {
|
||||||
|
bat "FOR /F 'tokens=5 delims= ' %%P IN ('netstat -ano ^| findstr :8989') DO TaskKill.exe /PID %%P"
|
||||||
|
}
|
||||||
|
|
||||||
|
withEnv(['JENKINS_NODE_COOKIE=dontkill']) {
|
||||||
|
if (isUnix()) {
|
||||||
|
sh 'nohup ./mvnw spring-boot:run -Dserver.port=8989 &'
|
||||||
|
sh "while ! httping -qc1 http://localhost:8989 ; do sleep 1 ; done"
|
||||||
|
sh "curl http://localhost:8989"
|
||||||
|
} else {
|
||||||
|
bat 'start ./mvnw.cmd spring-boot:run -Dserver.port=8989'
|
||||||
|
// Here we need to check(loop) if localhost:8989 is up
|
||||||
|
// Once it's we continue de script
|
||||||
|
bat "curl.exe http://localhost:8989"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue