Skip to content

Commit c067162

Browse files
author
Dassi Orleando
committed
Jenkins pipeline script for unix and non-unix OS
1 parent 6d36470 commit c067162

2 files changed

Lines changed: 93 additions & 1 deletion

File tree

‎spring-jenkins-pipeline/pom.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2222
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2323
<java.version>1.8</java.version>
24+
<checkstyle.version>2.17</checkstyle.version>
2425
</properties>
2526

2627
<dependencies>
@@ -48,7 +49,7 @@
4849
<plugin>
4950
<groupId>org.apache.maven.plugins</groupId>
5051
<artifactId>maven-checkstyle-plugin</artifactId>
51-
<version>2.17</version>
52+
<version>${checkstyle.version}</version>
5253
</plugin>
5354
</plugins>
5455
</build>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
node {
2+
stage 'Clone the project'
3+
git 'https://github.com/dassiorleando/tutorials.git'
4+
5+
dir('spring-jenkins-pipeline') {
6+
stage("Compilation and Analysis") {
7+
parallel 'Compilation': {
8+
if (isUnix()) {
9+
sh "./mvnw clean install -DskipTests"
10+
} else {
11+
bat "./mvnw.cmd clean install -DskipTests"
12+
}
13+
}, 'Static Analysis': {
14+
stage("Checkstyle") {
15+
if (isUnix()) {
16+
sh "./mvnw checkstyle:checkstyle"
17+
18+
step([$class: 'CheckStylePublisher',
19+
canRunOnFailed: true,
20+
defaultEncoding: '',
21+
healthy: '100',
22+
pattern: '**/target/checkstyle-result.xml',
23+
unHealthy: '90',
24+
useStableBuildAsReference: true
25+
])
26+
} else {
27+
bat "./mvnw.cmd checkstyle:checkstyle"
28+
29+
step([$class: 'CheckStylePublisher',
30+
canRunOnFailed: true,
31+
defaultEncoding: '',
32+
healthy: '100',
33+
pattern: '**\target\checkstyle-result.xml',
34+
unHealthy: '90',
35+
useStableBuildAsReference: true
36+
])
37+
}
38+
}
39+
}
40+
}
41+
42+
stage("Tests and Deployment") {
43+
parallel 'Unit tests': {
44+
stage("Runing unit tests") {
45+
if (isUnix()) {
46+
sh "./mvnw test -Punit"
47+
48+
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*UnitTest.xml'])
49+
} else {
50+
bat "./mvnw.cmd test -Punit"
51+
52+
step([$class: 'JUnitResultArchiver', testResults: '**\target\surefire-reports\TEST-*UnitTest.xml'])
53+
}
54+
}
55+
}, 'Integration tests': {
56+
stage("Runing integration tests") {
57+
if (isUnix()) {
58+
sh "./mvnw test -Pintegration"
59+
60+
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*IntegrationTest.xml'])
61+
} else {
62+
bat "./mvnw.cmd test -Pintegration"
63+
64+
step([$class: 'JUnitResultArchiver', testResults: '**\target\surefire-reports\TEST-*IntegrationTest.xml'])
65+
}
66+
}
67+
}, 'Deployment': {
68+
stage("Staging") {
69+
if (isUnix()) {
70+
sh "pid=\$(lsof -i:8989 -t); kill -TERM \$pid || kill -KILL \$pid"
71+
} else {
72+
bat "FOR /F 'tokens=5 delims= ' %%P IN ('netstat -ano ^| findstr :8989') DO TaskKill.exe /PID %%P"
73+
}
74+
75+
withEnv(['JENKINS_NODE_COOKIE=dontkill']) {
76+
if (isUnix()) {
77+
sh 'nohup ./mvnw spring-boot:run -Dserver.port=8989 &'
78+
sh "while ! httping -qc1 http://localhost:8989 ; do sleep 1 ; done"
79+
sh "curl http://localhost:8989"
80+
} else {
81+
bat 'start ./mvnw.cmd spring-boot:run -Dserver.port=8989'
82+
// Here we need to check(loop) if localhost:8989 is up
83+
// Once it's we continue de script
84+
bat "curl.exe http://localhost:8989"
85+
}
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)