Skip to content

Commit f3ead55

Browse files
committed
Add workspace cleanup to the script
1 parent f863146 commit f3ead55

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pipeline-examples/external-workspace-manager/externalWorkspace.groovy

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,21 @@ node('linux') {
1313
}
1414

1515
// on a different node, labeled 'test', perform testing using the same workspace as previously
16+
// at the end, if the build have passed, delete the workspace
1617
node('test') {
1718
// compute complete workspace path, from current node to the allocated disk
1819
exws(extWorkspace) {
19-
// run tests in the same workspace that the project was built
20-
sh 'mvn test'
20+
try {
21+
// run tests in the same workspace that the project was built
22+
sh 'mvn test'
23+
} catch (e) {
24+
// if any exception occurs, mark the build as failed
25+
currentBuild.result = 'FAILURE'
26+
throw e
27+
} finally {
28+
// perform workspace cleanup only if the build have passed
29+
// if the build has failed, the workspace will be kept
30+
step([$class: 'WsCleanup', cleanWhenFailure: false])
31+
}
2132
}
2233
}

0 commit comments

Comments
 (0)