-
Notifications
You must be signed in to change notification settings - Fork 8
/
Jenkinsfile
161 lines (147 loc) · 5.21 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
pipeline {
agent {
label 'worker'
}
options {
timeout(time: 30, unit: 'MINUTES')
}
tools {
maven 'Maven 3'
}
environment {
// START CUSTOM ohsome API
MAVEN_TEST_OPTIONS = '-Dport_get=8081 -Dport_post=8082 -Dport_data=8083 -DdbFilePathProperty=--database.db=/data/heidelberg-v1.0-beta.oshdb'
// END CUSTOM ohsome API
// this regex determines which branch is deployed as a snapshot
SNAPSHOT_BRANCH_REGEX = /(^main$)/
RELEASE_REGEX = /^([0-9]+(\.[0-9]+)*)(-(RC|beta-|alpha-)[0-9]+)?$/
RELEASE_DEPLOY = false
SNAPSHOT_DEPLOY = false
}
stages {
stage('Build and Test') {
steps {
// setting up a few basic env variables like REPO_NAME and LATEST_AUTHOR
setup_basic_env()
mavenbuild('clean compile javadoc:jar source:jar verify -P jacoco,sign,git')
}
post {
failure {
rocket_buildfail()
rocket_testfail()
}
}
}
stage('Reports and Statistics') {
steps {
reports_sonar_jacoco()
}
}
stage('Deploy Snapshot') {
when {
expression {
return env.BRANCH_NAME ==~ SNAPSHOT_BRANCH_REGEX && VERSION ==~ /.*-SNAPSHOT$/
}
}
steps {
deploy_snapshot('clean compile javadoc:jar source:jar deploy -P sign,git')
// START CUSTOM ohsome API
script {
SNAPSHOT_DEPLOY = true
}
// END CUSTOM ohsome API
}
post {
failure {
rocket_snapshotdeployfail()
}
}
}
stage('Deploy Release') {
when {
expression {
return VERSION ==~ RELEASE_REGEX && env.TAG_NAME ==~ RELEASE_REGEX
}
}
steps {
deploy_release('clean compile javadoc:jar source:jar deploy -P sign,git')
deploy_release_central('clean compile javadoc:jar source:jar deploy -P sign,git,deploy-central')
// START CUSTOM ohsome API
script {
RELEASE_DEPLOY = true
}
// END CUSTOM ohsome API
}
post {
failure {
rocket_releasedeployfail()
}
}
}
// START CUSTOM ohsome API
stage('Publish API Docs') {
when {
anyOf {
equals expected: true, actual: RELEASE_DEPLOY
equals expected: true, actual: SNAPSHOT_DEPLOY
}
}
agent {
label 'builtin'
}
steps {
script {
DOC_RELEASE_REGEX = /^([0-9]+(\.[0-9]+)*)$/
DOCS_DEPLOYMENT = 'development'
API_DOCS_PATH = 'development'
if (VERSION ==~ DOC_RELEASE_REGEX) {
DOCS_DEPLOYMENT = 'release'
API_DOCS_PATH = sh(returnStdout: true, script: 'cd docs && python3 get_pom_metadata.py | awk \'/^Path:/{ print $2 }\'').trim()
}
publish_dir = "/var/lib/jenkins/apidocs/${REPO_NAME}/${API_DOCS_PATH}/"
if (!fileExists('venv')) {
sh 'python3 -m venv venv'
}
sh """
# activate venv and install dependencies
. venv/bin/activate
venv/bin/pip install --upgrade pip
venv/bin/pip install -r docs/requirements.txt
cd docs
# compile
../venv/bin/sphinx-build -b html . _build
# publish
rm -rf ${publish_dir}
mkdir -p ${publish_dir}
cp -r _build/* ${publish_dir}
"""
}
}
post {
failure {
rocket_basicsend("Publishing of API Docs failed on ${env.BRANCH_NAME}")
}
}
}
// END CUSTOM ohsome API
stage('Check Dependencies') {
when {
expression {
if (currentBuild.number > 1) {
return (((currentBuild.getStartTimeInMillis() - currentBuild.previousBuild.getStartTimeInMillis()) > 2592000000) && (env.BRANCH_NAME ==~ SNAPSHOT_BRANCH_REGEX)) //2592000000 30 days in milliseconds
}
return false
}
}
steps {
check_dependencies()
}
}
stage('Wrapping Up') {
steps {
encourage()
status_change()
}
}
}
}