Skip to content

Commit cbf9bb1

Browse files
author
R. Tyler Croy
authored
Merge pull request #45 from alexsomai/external-workspace-manager
Basic example of External Workspace Manager Plugin usage
2 parents d1b719a + f3ead55 commit cbf9bb1

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Synopsis
2+
Shows how to allocate the same workspace on multiple nodes using the
3+
[External Workspace Manager Plugin](https://github.com/jenkinsci/external-workspace-manager-plugin).
4+
5+
# Prerequisites
6+
Before using this script, you must configure several prerequisites.
7+
A starting guide may be found in the
8+
[prerequisites](https://github.com/jenkinsci/external-workspace-manager-plugin/blob/master/doc/PREREQUISITES.md)
9+
section, from the plugin's documentation.
10+
11+
# Documentation
12+
Additional examples can be found on the plugin's
13+
[documentation page](https://github.com/jenkinsci/external-workspace-manager-plugin/blob/master/README.md),
14+
along with all the available features.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// allocate a Disk from the Disk Pool defined in the Jenkins global config
2+
def extWorkspace = exwsAllocate 'diskpool1'
3+
4+
// on a node labeled 'linux', perform code checkout and build the project
5+
node('linux') {
6+
// compute complete workspace path, from current node to the allocated disk
7+
exws(extWorkspace) {
8+
// checkout code from repo
9+
checkout scm
10+
// build project, but skip running tests
11+
sh 'mvn clean install -DskipTests'
12+
}
13+
}
14+
15+
// 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
17+
node('test') {
18+
// compute complete workspace path, from current node to the allocated disk
19+
exws(extWorkspace) {
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+
}
32+
}
33+
}

0 commit comments

Comments
 (0)