forked from BCDevOps/jenkins-pipeline-shared-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hasDirectoryChanged.groovy
32 lines (32 loc) · 1.01 KB
/
hasDirectoryChanged.groovy
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
// Checks for new changes to the context directory
def boolean call(String contextDirectory) {
// Determine if code has changed within the source context directory.
def changeLogSets = currentBuild.changeSets
def filesChangeCnt = 0
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
//echo "${entry.commitId} by ${entry.author} on ${new Date(entry.timestamp)}: ${entry.msg}"
def files = new ArrayList(entry.affectedFiles)
for (int k = 0; k < files.size(); k++) {
def file = files[k]
def filePath = file.path
//echo ">> ${file.path}"
if (filePath.contains(contextDirectory)) {
filesChangeCnt = 1
k = files.size()
j = entries.length
}
}
}
}
if ( filesChangeCnt < 1 ) {
echo('The changes do not require a build.')
return false
}
else {
echo('The changes require a build.')
return true
}
}