forked from sunshower-io/sunshower-devops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
233 lines (184 loc) · 6.85 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
pipeline {
agent {
kubernetes {
yamlFile 'deployments/agent/template.yaml'
}
}
environment {
/**
* credentials for Artifactory
*/
MVN_REPO = credentials('artifacts-credentials')
/**
* github credentials
*/
GITHUB = credentials('github-build-credentials')
/**
* this just contains the build email address and name
*/
GITHUB_USER = credentials("github-build-userinfo")
/**
* current version
*/
CURRENT_VERSION = readMavenPom(file: 'sunshower-env/pom.xml').getVersion()
}
stages {
stage('build env poms') {
steps {
container('maven') {
sh """
mvn clean install deploy \
-f sunshower-env \
-s sunshower-env/settings/settings.xml
"""
}
}
}
/**
* we could probably eventually handle this via plugin, but the process is
*
* Upon merge to master:
*
* 1. Increment the version number
* 2. Update the version-number in the POM files
* 3. Rebuild the Maven/Gradle projects
* 4. Upon success, increment to next snapshot
* 5. Upon failure, fail
* 6. Push next snapshot to master
*/
stage('deploy master snapshot') {
when {
branch 'master'
}
steps {
// scmSkip(deleteBuild: true, skipPattern: '\\[released\\].*')
container('maven') {
script {
segs = (env.CURRENT_VERSION - '-SNAPSHOT').split('\\.')
env.NEXT_VERSION = "${segs.join('.')}-${env.BUILD_NUMBER}-SNAPSHOT"
}
/**
* increment sunshower-env version
*/
sh """
mvn -f sunshower-env \
-s sunshower-env/settings/settings.xml \
versions:set -DnewVersion="${env.NEXT_VERSION}"
"""
/**
* deploy sunshower-env version
*/
sh """
mvn clean install deploy \
-f sunshower-env \
-s sunshower-env/settings/settings.xml
"""
}
}
}
stage("release component") {
when {
expression {
env.GIT_BRANCH == "release/${env.CURRENT_VERSION}"
}
}
steps {
// scmSkip(deleteBuild: true, skipPattern: '\\[released\\].*')
container('maven') {
script {
/**
* strip the leading "release/" prefix
*/
env.TAG_NAME = env.GIT_BRANCH - "release/"
/**
* compute the next versions:
*
* RELEASED_VERSION is the version that we're
* 1. building
* 2. deploying
* 3. tagging
*
* NEXT_VERSION is the version that main will be incremented to
*
* So, if CURRENT_VERSION = 1.0.0-SNAPSHOT,
* then RELEASED_VERSION = 1.0.0.Final
* and NEXT_VERSION = 1.0.1-SNAPSHOT
*/
version = env.CURRENT_VERSION
segs = (version - '-SNAPSHOT')
.split('\\.')
.collect { i ->
i as int
}
releasedVersion = (segs[0..-2] << ++segs[-1]).join('.')
nextVersion = releasedVersion + "-SNAPSHOT"
env.NEXT_VERSION = nextVersion
env.RELEASED_VERSION = "${releasedVersion}.Final"
}
/**
* configure github email address
*/
sh """
git config --global user.email "${GITHUB_USER_USR}"
"""
/**
* configure
*/
sh """
git config --global user.name "${GITHUB_USER_PSW}"
"""
sh """
mkdir -p ~/.ssh
"""
sh """
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
"""
sh """
git remote set-url origin https://${GITHUB_PSW}@github.com/sunshower-io/sunshower-devops
"""
sh """
mvn versions:set \
-f sunshower-env \
-s sunshower-env/settings/settings.xml \
-DnewVersion="${env.RELEASED_VERSION}"
"""
sh """
mvn clean install deploy \
-f sunshower-env \
-s sunshower-env/settings/settings.xml
"""
sh """
git tag "v${env.RELEASED_VERSION}" \
-m "[released] Tagging: ${env.RELEASED_VERSION} (from ${env.TAG_NAME})"
"""
sh """
git push origin "v${env.RELEASED_VERSION}"
"""
sh """
mvn versions:set \
-f sunshower-env \
-s sunshower-env/settings/settings.xml \
-DnewVersion="${env.NEXT_VERSION}"
"""
sh """
mvn clean install deploy \
-f sunshower-env \
-s sunshower-env/settings/settings.xml
"""
sh """
git commit -am "[released] ${env.TAG_NAME} -> ${env.RELEASED_VERSION}"
"""
sh """
git checkout -b master
"""
sh """
git pull --rebase origin master
"""
sh """
git push -u origin master
"""
}
}
}
}
}