-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
108 lines (95 loc) · 2.52 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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
timestamps
{
def jdk = 'openjdk-8-deb9'
//noinspection GroovyAssignabilityCheck
node(jdk)
{
try
{
abortable
{
echo("Delete working dir before build")
deleteDir()
def scmResult = checkout scm
computeGitTree(scmResult)
env.BUILD_TIMESTAMP = new Date().format("yyyy-MM-dd_HH-mm-ss");
env.JAVA_HOME = tool jdk
env.PATH = "${env.JAVA_HOME}/bin:${env.PATH}"
def antHome = tool 'Ant version 1.9.4'
sh "java -version"
sh "${antHome}/bin/ant -version"
def isRelease = env.BRANCH_NAME.toString().equals("master");
properties([
buildDiscarder(logRotator(
numToKeepStr : isRelease ? '1000' : '15',
artifactNumToKeepStr : isRelease ? '1000' : '2'
))
])
sh 'echo' +
' scmResult=' + scmResult +
' BUILD_TIMESTAMP -${BUILD_TIMESTAMP}-' +
' BRANCH_NAME -${BRANCH_NAME}-' +
' BUILD_NUMBER -${BUILD_NUMBER}-' +
' BUILD_ID -${BUILD_ID}-' +
' isRelease=' + isRelease
sh "${antHome}/bin/ant clean jenkins" +
' "-Dbuild.revision=${BUILD_NUMBER}"' +
' "-Dbuild.tag=git ${BRANCH_NAME} ' + scmResult.GIT_COMMIT + ' ' + scmResult.GIT_TREE + ' jenkins ${BUILD_NUMBER} ${BUILD_TIMESTAMP}"' +
' -Dbuild.status=' + (isRelease?'release':'integration') +
' -Dfindbugs.output=xml'
recordIssues(
failOnError: true,
enabledForFailure: true,
ignoreFailedBuilds: false,
qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]],
tools: [
java(),
spotBugs(pattern: 'build/findbugs.xml', useRankAsPriority: true),
],
)
archive 'build/success/*'
}
}
catch(Exception e)
{
//todo handle script returned exit code 143
throw e;
}
finally
{
def to = emailextrecipients([
[$class: 'CulpritsRecipientProvider'],
[$class: 'RequesterRecipientProvider']
])
//TODO details
step([$class: 'Mailer',
recipients: to,
attachLog: true,
notifyEveryUnstableBuild: true])
if('SUCCESS'.equals(currentBuild.result) ||
'UNSTABLE'.equals(currentBuild.result))
{
echo("Delete working dir after " + currentBuild.result)
deleteDir()
}
}
}
}
def abortable(Closure body)
{
try
{
body.call();
}
catch(hudson.AbortException e)
{
if(e.getMessage().contains("exit code 143"))
return
throw e;
}
}
def computeGitTree(scmResult)
{
sh "git cat-file -p " + scmResult.GIT_COMMIT + " | grep '^tree ' | sed -e 's/^tree //' > .git/jenkins-head-tree"
scmResult.GIT_TREE = readFile('.git/jenkins-head-tree').trim()
}