Last active
May 29, 2019 12:24
-
-
Save sytsereitsma/c9edbf1151e3acddc9cc to your computer and use it in GitHub Desktop.
[Jenkins] Delete project workspace on all nodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jenkins.model.Jenkins | |
String[] JOBS_TO_WIPE=[ | |
"CueingMiddleware", | |
"CueingMiddlewareH", | |
"HardwareDetector", | |
"RemoteParker" | |
] | |
void cleanNode(Node node, item_to_wipe) { | |
println("${node.name}:") | |
workspacePath = node.getWorkspaceFor(item_to_wipe) | |
if(!workspacePath){ | |
println(" Failed to find workspace path on ${node.name}.") | |
return | |
} | |
pathAsString = workspacePath.getRemote() | |
if (workspacePath.exists()) | |
{ | |
try { | |
workspacePath.deleteRecursive() | |
println(" Deleted from location " + pathAsString) | |
} | |
catch(IOException e) { | |
println(" Failed to delete from location " + pathAsString) | |
} | |
} | |
} | |
void wipeJob(String jobName) { | |
println("WIPING ${jobName}.") | |
println("--------------------------------------------.") | |
item_to_wipe = null | |
for (item in Jenkins.instance.items) { | |
if(item.name == jobName){ | |
item_to_wipe = item | |
break | |
} | |
} | |
if(!item_to_wipe){ | |
println("Failed to find Job with name ${jobName}") | |
} | |
else { | |
for (node in Jenkins.instance.getNodes()) { | |
cleanNode(node, item_to_wipe) | |
} | |
} | |
} | |
for (String jobName in JOBS_TO_WIPE) { | |
wipeJob(jobName) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment