-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.groovy
More file actions
68 lines (58 loc) · 1.94 KB
/
git.groovy
File metadata and controls
68 lines (58 loc) · 1.94 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def ga = "git add test".execute()
//def gcn = "git config user.name 'Nimble85'"
//def gce = "git config user.email '[email protected]'"
def gc = "git commit -ma"
def b = new StringBuffer()
def c = new StringBuffer()
ga.consumeProcessErrorStream(b)
gc.consumeProcessErrorStream(c)
//gcn.consumeProcessErrorStream(b)
//gce.consumeProcessErrorStream(b)
println ga.text
//println gcn.text
//println gce.text
println b.toString()
/*
def getGitCommit() {
git_commit = sh (
script: 'git rev-parse HEAD',
returnStdout: true
).trim()
return git_commit
}
*/
sshagent(['2456b422-7e08-4c76-aebb-3281647cdd14']) {
sh """
git add cocolab_pre
git config user.name 'jenkins'
git config user.email '[email protected]'
git commit --allow-empty -am 'jenkins ${JOB_NAME}-${BUILD_NUMBER}'
git tag -m "${BUILD_URL}" b"${BUILD_NUMBER}"
git pull --rebase origin master
"""
sh git push --tags origin master || \
git pull --rebase origin master || \
git push --tags origin master || \
git pull --rebase origin master || \
git push --tags origin master
try {
sh "git push --tags origin master"
} catch (err) {
sh "git pull --rebase origin master"
}
List<String> sourceChanged = sh(returnStdout: true, script: "git push --tags origin master").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!")
}
}