Skip to content

Commit 289c0b0

Browse files
committed
Implement a 'cleanWorkspace' option for wrappedNode
1 parent 491aaeb commit 289c0b0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

vars/wrappedNode.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ def call(Map vars, Closure body=null) {
55
withDockerRegistry(url: vars.get("registryUrl", "https://index.docker.io/v1/"), credentialsId: vars.get("registryCreds", "dockerbuildbot-index.docker.io")) {
66
wrap([$class: 'TimestamperBuildWrapper']) {
77
wrap([$class: 'AnsiColorBuildWrapper']) {
8+
if (vars.get('cleanWorkspace', false)) {
9+
// NOTE: `withChownWorkspace` uses docker. if our `label` doesn't have docker
10+
// or is misconfigured, these operations will fail and the exception will be
11+
// propogated.
12+
withChownWorkspace { echo "cleanWorkspace: Ensuring workspace is owned by ${env.USER}" }
13+
echo "cleanWorkspace: Removing existing workspace"
14+
deleteDir()
15+
echo "cleanWorkspace: Workspace is clean."
16+
}
817
if (body) { body() }
918
}
1019
}

vars/wrappedNode.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
<strong>wrappedNode(label: null, registryCreds: "dockerbuildbot-index.docker.io") { ... }</strong>
1+
<strong>wrappedNode(label: null, registryCreds: "dockerbuildbot-index.docker.io", cleanWorkspace: false) { ... }</strong>
22

33
<p>
44
Runs the given closure on a node matching <code>label</code> with the following behaviors:
55
<ul>
66
<li>Timestamps in build output</li>
77
<li>Colored output</li>
8-
<li>Logged into the Docker Registry with the credentials specified by thegiven ID</li>
8+
<li>Logged into the Docker Registry with the credentials specified by the given ID</li>
9+
<li>If cleanWorkspace is true, the workspace is removed (chowning the directory first).</li>
910
</ul>
1011
</p>

0 commit comments

Comments
 (0)