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