-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
41 lines (30 loc) · 1.19 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
node {
properties([
pipelineTriggers([
cron('H/5 * * * *')
])
])
def workspace = "C:\\ProgramData\\Jenkins\\.jenkins\\workspace\\"
def REPO_URL = "https://github.com/Ayushghagre/clearWorkspace.git"
currentBuild.result = "SUCCESS"
try {
stage("clearing up Workspace") {
def remoteBranches = bat(script: "git ls-remote --heads ${REPO_URL}", returnStdout: true).trim()
def branchList = remoteBranches.readLines()
.findAll { it.contains('refs/heads/') }
.collect { it.split()[1].replaceAll('refs/heads/', '') }
def command = "dir /B /A:D ${workspace}"
def workspaceDirs = bat(script: command, returnStdout: true).trim().readLines().drop(1)
workspaceDirs.each { dir ->
if (!branchList.contains(dir)) {
echo "Deleting workspace for branch: ${dir}"
bat "rmdir /S /Q ${workspace}\\${dir}"
}
}
}
} catch (Exception e) {
echo "Encountered An Exception"
currentBuild.result = "FAILURE"
echo e.toString()
}
}