forked from GIScience/oshdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
257 lines (229 loc) · 11.8 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
pipeline {
agent {label 'master'}
environment {
RELEASE_REGEX = /^([0-9]+(\.[0-9]+)*)(-(RC|beta-|alpha-)[0-9]+)?$/
RELEASE_DEPLOY = false
SNAPSHOT_DEPLOY = false
VERSION = sh(returnStdout: true, script: 'mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -Ev "(^\\[|Download\\w+)"').trim()
PACKAGING = sh(returnStdout: true, script: 'mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.packaging | grep -Ev "(^\\[|Download\\w+)"').trim()
GROUP_ID = sh(returnStdout: true, script: 'mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.groupId | grep -Ev "(^\\[|Download\\w+)"').trim()
ARTIFACT_ID = sh(returnStdout: true, script: 'mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.artifactId | grep -Ev "(^\\[|Download\\w+)"').trim()
}
stages {
stage ('Build and Test') {
steps {
script {
env.MAVEN_HOME = '/usr/share/maven'
author = sh(returnStdout: true, script: 'git show -s --pretty=%an')
echo author
commiti= sh(returnStdout: true, script: 'git log -1')
echo commiti
reponame=sh(returnStdout: true, script: 'basename `git remote get-url origin` .git').trim()
echo reponame
gittiid=sh(returnStdout: true, script: 'git describe --tags --long --always').trim()
echo gittiid
echo env.BRANCH_NAME
echo env.BUILD_NUMBER
echo env.TAG_NAME
server = Artifactory.server 'HeiGIT Repo'
rtMaven = Artifactory.newMavenBuild()
rtMaven.resolver server: server, releaseRepo: 'main', snapshotRepo: 'main'
rtMaven.deployer server: server, releaseRepo: 'libs-release-local', snapshotRepo: 'libs-snapshot-local'
rtMaven.deployer.deployArtifacts = false
withCredentials([string(credentialsId: 'gpg-signing-key-passphrase', variable: 'PASSPHRASE')]) {
buildInfo = rtMaven.run pom: 'pom.xml', goals: 'clean compile javadoc:jar source:jar install -P sign,git,withDep -Dmaven.repo.local=.m2 -Dgpg.passphrase=$PASSPHRASE'
}
}
}
post {
failure {
rocketSend channel: 'jenkinsohsome', emoji: ':sob:' , message: "oshdb-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}. Review the code!" , rawMessage: true
}
}
}
stage ('Deploy Snapshot') {
when {
expression {
return env.BRANCH_NAME ==~ /(^master$)/ && VERSION ==~ /.*-SNAPSHOT$/
}
}
steps {
script {
rtMaven.deployer.deployArtifacts buildInfo
server.publishBuildInfo buildInfo
SNAPSHOT_DEPLOY = true
}
}
post {
failure {
rocketSend channel: 'jenkinsohsome', message: "Deployment of oshdb-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}. Is Artifactory running?" , rawMessage: true
}
}
}
stage ('Deploy Release') {
when {
expression {
return VERSION ==~ RELEASE_REGEX && env.TAG_NAME ==~ RELEASE_REGEX
}
}
steps {
script {
rtMaven.deployer.deployArtifacts buildInfo
server.publishBuildInfo buildInfo
RELEASE_DEPLOY = true
}
withCredentials([
file(credentialsId: 'ossrh-settings', variable: 'settingsFile'),
string(credentialsId: 'gpg-signing-key-passphrase', variable: 'PASSPHRASE')
]) {
// copy of the above build, since "deploy" does rebuild the packages, without withDep profile
sh 'mvn -s $settingsFile javadoc:jar source:jar deploy -P sign,git,deploy-central -Dmaven.repo.local=.m2 -Dgpg.passphrase=$PASSPHRASE -DskipTests=true'
}
}
post {
failure {
rocketSend channel: 'jenkinsohsome', message: "Deployment of oshdb-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}. Is Artifactory running?" , rawMessage: true
}
}
}
stage ('Trigger Benchmark and build Examples') {
when {
expression {
return env.BRANCH_NAME ==~ /(^master$)/
}
}
steps {
build job: 'oshdb-benchmark/master', quietPeriod: 360, wait: false
build job: 'oshdb-examples/master', quietPeriod: 360, wait: false
}
post {
failure {
rocketSend channel: 'jenkinsohsome', message: "Triggering of Benchmarks or Examples for oshdb-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Does the benchmark job still exist?" , rawMessage: true
}
}
}
stage ('Publish Javadoc') {
when {
anyOf {
equals expected: true, actual: RELEASE_DEPLOY
equals expected: true, actual: SNAPSHOT_DEPLOY
}
}
steps {
script {
//load dependencies to artifactory
rtMaven.run pom: 'pom.xml', goals: 'org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version -Dmaven.repo.local=.m2'
javadc_dir="/srv/javadoc/java/" + reponame + "/" + VERSION + "/"
echo javadc_dir
rtMaven.run pom: 'pom.xml', goals: 'clean javadoc:javadoc -Dadditionalparam=-Xdoclint:none -Dmaven.repo.local=.m2'
sh "echo $javadc_dir"
//make sure jenkins uses bash not dash!
sh "mkdir -p $javadc_dir && rm -Rf $javadc_dir* && find . -path '*/target/site/apidocs' -exec cp -R --parents {} $javadc_dir \\; && find $javadc_dir -path '*/target/site/apidocs' | while read line; do echo \$line; neu=\${line/target\\/site\\/apidocs/} ; mv \$line/* \$neu ; done && find $javadc_dir -type d -empty -delete"
}
script {
javadc_dir=javadc_dir + "aggregated/"
rtMaven.run pom: 'pom.xml', goals: 'clean javadoc:aggregate -Dadditionalparam=-Xdoclint:none -Dmaven.repo.local=.m2'
sh "mkdir -p $javadc_dir && rm -Rf $javadc_dir* && find . -path './target/site/apidocs' -exec cp -R --parents {} $javadc_dir \\; && find $javadc_dir -path '*/target/site/apidocs' | while read line; do echo \$line; neu=\${line/target\\/site\\/apidocs/} ; mv \$line/* \$neu ; done && find $javadc_dir -type d -empty -delete"
}
}
post {
failure {
rocketSend channel: 'jenkinsohsome', message: "Deployment of javadoc oshdb-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}." , rawMessage: true
}
}
}
stage ('Reports and Statistics') {
steps {
script {
//jacoco
report_dir="/srv/reports/" + reponame + "/" + VERSION + "_" + env.BRANCH_NAME + "/" + env.BUILD_NUMBER + "_" +gittiid+"/jacoco/"
rtMaven.run pom: 'pom.xml', goals: 'clean verify -Pjacoco -Dmaven.repo.local=.m2'
sh "mkdir -p $report_dir && rm -Rf $report_dir* && find . -path '*/target/site/jacoco' -exec cp -R --parents {} $report_dir \\; && find $report_dir -path '*/target/site/jacoco' | while read line; do echo \$line; neu=\${line/target\\/site\\/jacoco/} ; mv \$line/* \$neu ; done && find $report_dir -type d -empty -delete"
//infer
if(env.BRANCH_NAME ==~ /(^master$)/) {
report_dir="/srv/reports/" + reponame + "/" + VERSION + "_" + env.BRANCH_NAME + "/" + env.BUILD_NUMBER + "_" +gittiid+"/infer/"
sh "mvn clean"
sh "infer run -r -- mvn compile"
sh "mkdir -p $report_dir && rm -Rf $report_dir* && cp -R ./infer-out/* $report_dir"
}
//warnings plugin
rtMaven.run pom: 'pom.xml', goals: '--batch-mode -V -e checkstyle:checkstyle pmd:pmd pmd:cpd findbugs:findbugs com.github.spotbugs:spotbugs-maven-plugin:3.1.7:spotbugs -Dmaven.repo.local=.m2'
recordIssues enabledForFailure: true, tools: [mavenConsole(), java(), javaDoc()]
recordIssues enabledForFailure: true, tool: checkStyle()
recordIssues enabledForFailure: true, tool: findBugs()
recordIssues enabledForFailure: true, tool: spotBugs()
recordIssues enabledForFailure: true, tool: cpd(pattern: '**/target/cpd.xml')
recordIssues enabledForFailure: true, tool: pmdParser(pattern: '**/target/pmd.xml')
}
}
post {
failure {
rocketSend channel: 'jenkinsohsome', message: "Reporting of oshdb-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}." , rawMessage: true
}
}
}
stage ('Check Dependencies') {
when {
expression {
if(currentBuild.number > 1) {
monthpre=new Date(currentBuild.previousBuild.rawBuild.getStartTimeInMillis())[Calendar.MONTH]
echo monthpre.toString()
monthnow=new Date(currentBuild.rawBuild.getStartTimeInMillis())[Calendar.MONTH]
echo monthnow.toString()
return monthpre!=monthnow
}
return false
}
}
steps {
script {
updatenotify=sh(returnStdout: true, script: 'mvn versions:display-dependency-updates | grep -Pzo "(?s)The following dependencies.*\\n.* \\n"').trim()
echo updatenotify
}
rocketSend channel: 'jenkinsohsome', emoji: ':wave:' , message: "You might have updates in your dependecies: ${updatenotify}" , rawMessage: true
}
post {
failure {
rocketSend channel: 'jenkinsohsome', emoji: ':disappointed:' , message: "Checking for updates in oshdb-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}." , rawMessage: true
}
}
}
stage ('Encourage') {
when {
expression {
if(currentBuild.number > 1) {
datepre=new Date(currentBuild.previousBuild.rawBuild.getStartTimeInMillis()).clearTime()
echo datepre.format( 'yyyyMMdd' )
datenow=new Date(currentBuild.rawBuild.getStartTimeInMillis()).clearTime()
echo datenow.format( 'yyyyMMdd' )
return datepre.numberAwareCompareTo(datenow)<0
}
return false
}
}
steps {
rocketSend channel: 'jenkinsohsome', message: "Hey, this is just your daily notice that Jenkins is still working for you on OSHDB-Branch ${env.BRANCH_NAME}! Happy and for free! Keep it up!" , rawMessage: true
}
post {
failure {
rocketSend channel: 'jenkinsohsome', emoji: ':wink:' , message: "Reporting of oshdb-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}." , rawMessage: true
}
}
}
stage ('Report Status Change') {
when {
expression {
return ((currentBuild.number > 1) && (currentBuild.getPreviousBuild().result == 'FAILURE'))
}
}
steps {
rocketSend channel: 'jenkinsohsome', message: "We had some problems, but we are BACK TO NORMAL! Nice debugging: oshdb-build-nr. ${env.BUILD_NUMBER} *succeeded* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}." , rawMessage: true
}
post {
failure {
rocketSend channel: 'jenkinsohsome', message: "Reporting of oshdb-build nr. ${env.BUILD_NUMBER} *failed* on Branch - ${env.BRANCH_NAME} (<${env.BUILD_URL}|Open Build in Jenkins>). Latest commit from ${author}." , rawMessage: true
}
}
}
}
}