-
Notifications
You must be signed in to change notification settings - Fork 70
/
Jenkinsfile
284 lines (250 loc) · 8.59 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!groovy
pipeline {
agent any
options {
disableConcurrentBuilds()
timestamps()
skipDefaultCheckout()
buildDiscarder(logRotator(numToKeepStr: '10'))
}
stages {
stage('Checkout') {
steps{
retry(3) {
timeout(time: 30, unit: 'SECONDS') {
script {
checkout()
}
}
}
}
}
stage('Compile') {
steps{
script {
compile()
analyze()
}
}
}
stage('Archive') {
steps{
script {
archive = archive()
}
}
}
stage('Publish') {
steps{
script {
publish(archive)
publishRelease(archive)
}
}
}
}
post {
always {
deleteDir()
}
}
}
///////////////////////////////////
def checkout() {
deleteDir()
checkout([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [[$class: 'CleanCheckout'], [$class: 'CloneOption', depth: 100, noTags: false, reference: '', shallow: true]],
userRemoteConfigs: scm.userRemoteConfigs
])
sh('git rev-parse HEAD > GIT_COMMIT')
git_commit=readFile('GIT_COMMIT')
def short_commit=git_commit.take(6)
//currentBuild.setName("${short_commit}__${env.BUILD_NUMBER}")
currentBuild.setDescription("${env.BRANCH_NAME} - ${short_commit}")
}
def compile() {
sh "chmod u+x mvnw"
def product
if(env.BRANCH_NAME=="master")
product=",build-product"
else
product=""
profiles="help${product}"
wrap([$class: 'Xvfb', displayNameOffset: 100, installationName: 'xvfb', screen: '1024x768x24']) {
sh "PATH=$PATH:~jenkins/erlide_tools && ./mvnw -B -U clean verify -P ${profiles} -Dmaven.test.failure.ignore=true"
}
if(env.BRANCH_NAME=="master") {
// TODO rename product artifacts
}
}
def analyze() {
step([$class: 'WarningsPublisher', canComputeNew: false, canResolveRelativePaths: false,
consoleParsers: [[parserName: 'Java Compiler (Eclipse)']],
excludePattern: '', healthy: '', includePattern: '', messagesPattern: '', unHealthy: ''])
step([$class: 'TasksPublisher', canComputeNew: false, excludePattern: '', healthy: '', high: 'FIXME,XXX', low: '', normal: 'TODO', pattern: '**/*.java,**/*.?rl,**/*.xtend', unHealthy: ''])
step([$class: 'AnalysisPublisher', canComputeNew: false, healthy: '', unHealthy: ''])
step([$class: 'JUnitResultArchiver', allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml'])
step([$class: 'JacocoPublisher', exclusionPattern: '**/*Test*.class,org/erlide/wrangler/**/*,org/erlide/cover/**/*,org/erlide/tracing/**/*,org/incava/**/*,com/ericsson/**/*,org/erlide/annotations/**/*,org/erlide/util/CharOperation,org/erlide/util/Util', sourcePattern: '**/src/'])
}
def archive() {
sh 'rm -rf VSN'
sh 'ls releng/org.erlide.site/target/repository/features/org.erlide_*.jar | xargs basename > VSN || true'
def archive = readFile('VSN').trim().replace('.jar', '.zip')
if(archive != '') {
dir('releng/org.erlide.site/target/repository') {
sh "zip -r ${archive} * "
step([$class: 'ArtifactArchiver', artifacts: archive, fingerprint: true])
}
}
if(env.BRANCH_NAME=="master") {
step([$class: 'ArtifactArchiver', artifacts: 'releng/org.erlide.product.site/target/products/*.zip', fingerprint: true])
}
return archive
}
@NonCPS
def getVersion(String archive) {
def m = (archive =~ /org.erlide_([0-9]+\.[0-9]+\.[0-9]+)(\.(.+))?.zip/)
return m[0]
}
def publish(def archive) {
sh "git remote get-url origin > REPO"
def isMainRepo = readFile('REPO').trim().contains('github.com/erlang/')
if(!isMainRepo) {
// only do a release if in main repo
return
}
// FIXME we can't push to https git url, needs password... Jenkins Github plugin uses https...
//return
def v = getVersion(archive)
def vsn = v[1]
def ts = v[2]
def repo
switch (env.BRANCH_NAME) {
case "release": repo = "beta"; break
case "master" : repo = "releases"; break
default: repo = "nightly"
}
def kind
switch (env.BRANCH_NAME) {
case "release": kind = "B"; break
case "master" : kind = "R"; break
case "pu" : kind = "A"; break
default: kind = ""
}
def dest
if(kind == "R") {
dest = vsn
} else {
dest = "${vsn}_${kind}${ts}"
}
def output_base = "/media/www/download.erlide.org/update"
def full_dest = "${output_base}/archive/${repo}/${dest}"
sh "umask 002"
sh "mkdir -p ${full_dest}"
sh "cp -r releng/org.erlide.site/target/repository/* ${full_dest}"
sh "chown -R :www-data ${full_dest}"
if(kind == "R") {
p2_add_composite(full_dest, output_base)
generate_version_info(vsn, output_base)
} else if(kind != "") {
sh "rm -f ${output_base}/${repo}"
sh "ln -s ${full_dest} ${output_base}/${repo}"
}
}
def run_eclipse(def dir, def opts) {
def launcher = new File("${dir}/plugins").list().grep(~/org.eclipse.equinox.launcher_.*.jar/)
sh "java -jar ${launcher} ${opts} -verbose"
}
def p2_add_composite(def dir, def base) {
def relpath = java.nio.file.Paths.get(base).relativize(java.nio.file.Paths.get(dir)).toString()
sh "chmod u+x releng/org.erlide.releng/comp-repo.sh && releng/org.erlide.releng/comp-repo.sh ${base} --eclipse ${env.HOME}/erlide_tools/buckminster/ add ${relpath}"
}
def generate_version_info(def vsn, def base) {
sh 'git describe --tags > GIT_INFO'
def info = readFile('GIT_INFO').trim()
writeFile file: "${base}/info.js", text: "document.write('${info}');"
writeFile file: "${base}/version.js", text: "document.write('${vsn}');"
writeFile file: "${base}/id.js", text: "document.write('${env.BUILD_ID}');"
writeFile file: "${base}/version.txt", text: "${vsn}"
}
def publishRelease(def archive) {
def isMaster = (env.BRANCH_NAME=='master')
sh "git remote get-url origin > REPO"
def isMainRepo = readFile('REPO').trim().contains('github.com/erlang/')
if(!isMaster || !isMainRepo) {
// only do a github release if on master and in main repo
return
}
def v = getVersion(archive)
def vsn = v[1]
def ts = v[2]
def vvsn = "v${vsn}"
//sh "git push origin :refs/tags/${vvsn} || true"
sh "git fetch --prune origin +refs/tags/*:refs/tags/*"
sh 'rm -rf GIT_TAG'
sh 'git describe --exact-match > GIT_TAG || true'
def git_tag = readFile('GIT_TAG').trim()
if(git_tag != vvsn) {
// if there is a tag, but it's not $vvsn, skip publishing
return
}
if(git_tag == null || git_tag == '') {
sh "git tag -a ${vvsn} -m ${vvsn}"
//sh "git push origin ${vvsn}"
//git_tag = vvsn
}
def draft = true
def body = ""
def owner = "erlang"
def repository = "erlide_eclipse"
def access_token = "${env.GITHUB_TOKEN}"
sh "rm -rf RELEASE"
def API_create="{\"tag_name\": \"${vvsn}\",\"name\": \"${vvsn}\",\"body\": \"${body}\",\"draft\": ${draft},\"prerelease\": false}"
sh "curl -H \"Content-Type:application/json\" --data '${API_create}' https://api.github.com/repos/${owner}/${repository}/releases?access_token=${access_token} > RELEASE"
def release = readFile('RELEASE').trim()
def info = getReleaseInfo(release)
def release_id = info[1]
sh "curl -X POST --header \"Content-Type:application/edn\" --data-binary @releng/org.erlide.site/target/repository/${archive} https://uploads.github.com/repos/${owner}/${repository}/releases/${release_id}/assets?access_token=${access_token}\\&name=${archive}"
// publish help to github.io
val dest = "plugins/org.erlide.help/target/erlide.github.io"
sh "rm -rf ${dest} && mkdir -p ${dest}"
sh "git clone --depth 1 [email protected]:erlide/erlide.github.io -b master ${dest}"
sh "cp -R plugins/org.erlide.help/articles/* ${dest}/articles/eclipse"
dir(dest) {
sh "git add . && git commit -a -m 'autoupdate eclipse docs (${vsn})' && git push origin master"
}
}
@NonCPS
def getReleaseInfo(String data) {
def m = (data.replaceAll("\n"," ").trim() =~ /\{[^{]*"id": *([^,]*),.*/)
return m[0]
}
def getRepoURL() {
sh "git config --get remote.origin.url > .git/remote-url"
return readFile(".git/remote-url").trim()
}
def getCommitSha() {
sh "git rev-parse HEAD > .git/current-commit"
return readFile(".git/current-commit").trim()
}
def updateGithubCommitStatus(build) {
// workaround https://issues.jenkins-ci.org/browse/JENKINS-38674
repoUrl = getRepoURL()
commitSha = getCommitSha()
step([
$class: 'GitHubCommitStatusSetter',
reposSource: [$class: "ManuallyEnteredRepositorySource", url: repoUrl],
commitShaSource: [$class: "ManuallyEnteredShaSource", sha: commitSha],
errorHandlers: [[$class: 'ShallowAnyErrorHandler']],
statusResultSource: [
$class: 'ConditionalStatusResultSource',
results: [
[$class: 'BetterThanOrEqualBuildResult', result: 'SUCCESS', state: 'SUCCESS', message: build.description],
[$class: 'BetterThanOrEqualBuildResult', result: 'FAILURE', state: 'FAILURE', message: build.description],
[$class: 'AnyBuildResult', state: 'FAILURE', message: 'Loophole']
]
]
])
}