-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit1.groovy
More file actions
36 lines (36 loc) · 1.51 KB
/
git1.groovy
File metadata and controls
36 lines (36 loc) · 1.51 KB
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
#!groovy
pipeline {
stages {
stage('Check for CHANGELOG update') {
when { expression { env.BRANCH_NAME != 'master' } }
steps {
script {
sshagent(['CREDENTIAL_NAME']) {
sh "git config --add remote.origin.fetch +refs/heads/master:refs/remotes/origin/master"
sh "git fetch --no-tags"
List<String> sourceChanged = sh(returnStdout: true, script: "git diff --name-only origin/master..origin/${env.BRANCH_NAME}").split()
def isSourceChanged = false
def isChangelogUpdated = false
for (int i = 0; i < sourceChanged.size(); i++) {
if (sourceChanged[i].contains("src")) {
isSourceChanged = true
}
if (sourceChanged[i].contains("CHANGELOG")) {
isChangelogUpdated = true
}
}
// Changelog not updated after changing source, fail build and notify
if (isSourceChanged && !isChangelogUpdated) {
error("Source files changed but CHANGELOG was not updated!")
}
}
}
}
post {
failure {
// post to Slack
}
}
}
}
}