Merge pull request #3302 from dassiorleando/master

BAEL-720: better handle failed test in Jenkins pipeline
This commit is contained in:
Loredana Crusoveanu 2017-12-27 19:47:33 +02:00 committed by GitHub
commit 13b9b3d9e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 24 deletions

View File

@ -31,38 +31,48 @@ node {
stage("Tests and Deployment") { stage("Tests and Deployment") {
parallel 'Unit tests': { parallel 'Unit tests': {
stage("Runing unit tests") { stage("Running unit tests") {
if (isUnix()) { try {
sh "./mvnw test -Punit" if (isUnix()) {
} else { sh "./mvnw test -Punit"
bat "./mvnw.cmd test -Punit" } else {
bat "./mvnw.cmd test -Punit"
}
} catch(err) {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*UnitTest.xml'])
throw err
} }
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*UnitTest.xml']) step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*UnitTest.xml'])
} }
}, 'Integration tests': { }, 'Integration tests': {
stage("Runing integration tests") { stage("Running integration tests") {
if (isUnix()) { try {
sh "./mvnw test -Pintegration" if (isUnix()) {
} else { sh "./mvnw test -Pintegration"
bat "./mvnw.cmd test -Pintegration" } else {
bat "./mvnw.cmd test -Pintegration"
}
} catch(err) {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*IntegrationTest.xml'])
throw err
} }
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*IntegrationTest.xml']) 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= \" %%G IN (\"netstat -a | findstr :8989\") DO TaskKill.exe /PID %%G /fi \"memusage gt 0\""
}
withEnv(['JENKINS_NODE_COOKIE=dontkill']) { stage("Staging") {
if (isUnix()) { if (isUnix()) {
sh 'nohup ./mvnw spring-boot:run -Dserver.port=8989 &' sh "pid=\$(lsof -i:8989 -t); kill -TERM \$pid || kill -KILL \$pid"
} else { } else {
bat 'start ./mvnw.cmd spring-boot:run -Dserver.port=8989' 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'
} }
} }
} }

View File

@ -6,6 +6,6 @@ import static org.junit.Assert.*;
public class SomeUnitTest { public class SomeUnitTest {
@Test @Test
public void init() { public void init() {
assertEquals(1, 0); assertEquals(1, 1);
} }
} }