-
Notifications
You must be signed in to change notification settings - Fork 10
/
Jenkinsfile
180 lines (157 loc) · 4.73 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
#!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()
analyze1()
}
}
}
stage('Test') {
steps{
script {
test()
analyze2()
}
}
}
stage('Eclipse') {
steps{
script {
buildEclipse()
publishEclipse()
}
}
}
}
//post {
//always {
//deleteDir()
//}
//}
}
///////////////////////////////////
def checkout() {
deleteDir()
checkout scm
git_branch = env.BRANCH_NAME
sh('git rev-parse HEAD > GIT_COMMIT')
git_commit=readFile('GIT_COMMIT')
short_commit=git_commit.take(6)
currentBuild.setDescription("${git_branch} - ${short_commit}")
}
def compile() {
sh "chmod u+x build"
sh "./build"
sleep 2L
}
def test() {
sh "chmod u+x build"
sh "./build test"
sleep 2L
sh "find . -name \"TEST-*.xml\" -exec xargs rename -v 's/\"//' {} \\;"
}
def analyze1() {
step([$class: 'WarningsPublisher', canComputeNew: false, canResolveRelativePaths: true, canRunOnFailed: true,
consoleParsers: [[parserName: 'Erlang Compiler (erlc)'], [parserName: 'Maven']],
excludePattern: '', healthy: '', includePattern: '', messagesPattern: '', unHealthy: ''])
step([$class: 'TasksPublisher', canComputeNew: false, excludePattern: '**/_build/**/*.*', healthy: '', high: 'FIXME,XXX', low: '', normal: 'TODO', pattern: '**/*.erl,**/*.hrl', unHealthy: ''])
}
def analyze2() {
step([$class: 'AnalysisPublisher', canComputeNew: false, healthy: '', unHealthy: ''])
step([$class: 'JUnitResultArchiver', allowEmptyResults: true, testResults: '**/TEST*.xml'])
//step([$class: 'JacocoPublisher', exclusionPattern: '', sourcePattern: '**/src/'])
// we need Cobertura...
// publishHTML([
// allowMissing: false,
// alwaysLinkToLastBuild: false,
// keepAll: true,
// reportDir: '',
// reportFiles:
// '''common/_build/test/index.html
// ''',
// reportName: 'Coverage Report'
// ])
}
def buildEclipse() {
sh "cd eclipse && ./build && cd .."
step([$class: 'ArtifactArchiver', artifacts: "eclipse/org.erlide.kernel.site-*.zip", fingerprint: true])
}
@NonCPS
def getVersion(String archive) {
def m = (archive =~ /org.erlide.kernel[-_]([0-9]+\.[0-9]+\.[0-9]+)(\.(.+))?.zip/)
return m[0]
}
def publishEclipse() {
def archive = "org.erlide.kernel.site-.zip"
def isMaster = (git_branch=='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
}
// TODO not working for now
return
def v = getVersion(archive)
def vsn = v[1]
def ts = v[2]
def vvsn = "v${vsn}"
// FIXME we can't push to https git url, needs password... Jenkins Github plugin uses https...
//sh "git push origin :refs/tags/${vvsn}"
//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 == null || git_tag == '') {
sh "git tag -a ${vvsn} -m ${vvsn}"
//sh "git push origin ${vvsn}"
git_tag = vvsn
}
if(git_tag != vvsn) {
// if there is a tag, but it's not $vvsn, skip publishing
return
}
def draft = true
def body = ""
def owner = "erlang"
def repository = "erlide_kernel"
def access_token = "${env.GITHUB_TOKEN___}" // the token will be printed in console output...
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)
if(info != null) {
def release_id = info[1]
sh "curl -X POST --header \"Content-Type:application/edn\" --data-binary @target/${archive} https://uploads.github.com/repos/${owner}/${repository}/releases/${release_id}/assets?access_token=${access_token}\\&name=${archive}"
}
}
@NonCPS
def getReleaseInfo(String data) {
def m = (data.replaceAll("\n"," ").trim() =~ /\{[^{]*"id": *([^,]*),.*/)
if(!m) return null
return m[0]
}
def publishServer() {
}