forked from samrocketman/jenkins-bootstrap-jervis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
372 lines (346 loc) · 14.4 KB
/
build.gradle
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.netflix.nebula:gradle-ospackage-plugin:4.0.0'
}
}
//RPM package building
apply plugin: 'nebula.ospackage'
//gradle plugins
apply plugin: 'maven'
//default
defaultTasks 'getjenkins', 'getplugins'
import org.apache.tools.ant.filters.ReplaceTokens
import org.redline_rpm.header.Flags
//perhaps use JENKINS_HOME some day
//avoiding JENKINS_HOME because I only want to copy if file doesn't exist
//by default the copy function will overwrite plugins in JENKINS_HOME if the hash is different
ext.jenkinsHome = System.getenv('JENKINS_HOME')?:'../my_jenkins_home'
ext.bootstrapHome = System.getenv('BOOTSTRAP_HOME')?:'.'
ext.pluginsDest = bootstrapHome
ext.jenkinsDest = bootstrapHome
//tokens for Jenkins packaging
//note: tokens do not auto-correct when rpm prefix is customized during install
ext.tokens = [
ARTIFACTNAME: System.getenv('ARTIFACTNAME')?:'jenkins',
AUTHOR: System.getenv('AUTHOR')?:'Sam Gleske <[email protected]>',
CAMELARTIFACTNAME: System.getenv('CAMELARTIFACTNAME')?:'Jenkins',
CHANGELOG_PAGE: System.getenv('CHANGELOG_PAGE')?:'http://jenkins.io/changelog',
COMMIT: ['git', 'rev-parse', 'HEAD'].execute().text.toString().trim(),
HOME: System.getenv('JENKINS_HOME')?:'/var/lib/jenkins', //JENKINS_HOME
HOMEPAGE: System.getenv('HOMEPAGE')?:'https://github.com/samrocketman/jenkins-bootstrap-jervis',
LICENSE: 'MIT/X License, GPL/CDDL, ASL2',
LICENSE_FILE: System.getenv('LICENSE_FILE')?:'LICENSE',
MANIFEST: 'jenkins-versions.manifest',
PACKAGENAME: System.getenv('PACKAGENAME')?:'jenkins-bootstrap',
PORT: System.getenv('PORT')?:'8080',
PREFIX: '/usr',
PRODUCTNAME: 'Jenkins',
SUMMARY: System.getenv('SUMMARY')?:'Jenkins Continuous Integration Server',
USER: System.getenv('JENKINS_USER')?:'jenkins',
VENDOR: System.getenv('VENDOR')?:'jenkins-bootstrap by Sam Gleske'
]
ext.tokens['WAR'] = "${ext.tokens['PREFIX']}/lib/${ext.tokens['ARTIFACTNAME']}/${ext.tokens['ARTIFACTNAME']}.war".toString()
//version of Jenkins to download
version = '2.32.3'
description = "Built from jenkins-bootstrap-jervis @ ${tokens['COMMIT']}"
task cleanJenkins(type: Delete) {
doFirst {
//stop jenkins just in case it's running
def stdout = new StringBuilder()
def stderr = new StringBuilder()
def process = ["${bootstrapHome}/scripts/provision_jenkins.sh", 'purge'].execute()
process.waitForProcessOutput(stdout, stderr)
println stdout.toString()
println stderr.toString()
}
delete '.gradle'
delete 'plugins'
}
clean.dependsOn cleanJenkins
configurations {
getplugins {
description = 'Download Jenkins plugins .jpi files.'
transitive = false
}
getjenkins {
description = 'Download Jenkins WAR file.'
transitive = false
}
}
repositories {
maven {
name 'jenkins'
delegate.url('https://repo.jenkins-ci.org/public/')
}
}
dependencies {
//get Jenkins
getjenkins "org.jenkins-ci.main:jenkins-war:${version}@war"
//get plugins
getplugins 'com.coravy.hudson.plugins.github:github:1.26.1@hpi'
getplugins 'com.github.kostyasha.yet-another-docker:yet-another-docker-plugin:0.1.0-rc31@hpi'
getplugins 'jp.ikedam.jenkins.plugins:groovy-label-assignment:1.2.0@hpi'
getplugins 'org.jenkins-ci.main:maven-plugin:2.15.1@hpi'
getplugins 'org.jenkins-ci.plugins.icon-shim:icon-shim:2.0.3@hpi'
getplugins 'org.jenkins-ci.plugins.pipeline-stage-view:pipeline-rest-api:2.6@hpi'
getplugins 'org.jenkins-ci.plugins.pipeline-stage-view:pipeline-rest-api:2.6@hpi'
getplugins 'org.jenkins-ci.plugins.pipeline-stage-view:pipeline-stage-view:2.6@hpi'
getplugins 'org.jenkins-ci.plugins.workflow:workflow-aggregator:2.5@hpi'
getplugins 'org.jenkins-ci.plugins.workflow:workflow-api:2.12@hpi'
getplugins 'org.jenkins-ci.plugins.workflow:workflow-basic-steps:2.4@hpi'
getplugins 'org.jenkins-ci.plugins.workflow:workflow-cps-global-lib:2.7@hpi'
getplugins 'org.jenkins-ci.plugins.workflow:workflow-cps-global-lib:2.7@hpi'
getplugins 'org.jenkins-ci.plugins.workflow:workflow-cps:2.29@hpi'
getplugins 'org.jenkins-ci.plugins.workflow:workflow-durable-task-step:2.9@hpi'
getplugins 'org.jenkins-ci.plugins.workflow:workflow-job:2.10@hpi'
getplugins 'org.jenkins-ci.plugins.workflow:workflow-multibranch:2.13@hpi'
getplugins 'org.jenkins-ci.plugins.workflow:workflow-scm-step:2.4@hpi'
getplugins 'org.jenkins-ci.plugins.workflow:workflow-step-api:2.9@hpi'
getplugins 'org.jenkins-ci.plugins.workflow:workflow-support:2.13@hpi'
getplugins 'org.jenkins-ci.plugins:ant:1.4@hpi'
getplugins 'org.jenkins-ci.plugins:antisamy-markup-formatter:1.5@hpi'
getplugins 'org.jenkins-ci.plugins:authentication-tokens:1.3@hpi'
getplugins 'org.jenkins-ci.plugins:bouncycastle-api:2.16.0@hpi'
getplugins 'org.jenkins-ci.plugins:branch-api:2.0.8@hpi'
getplugins 'org.jenkins-ci.plugins:cloud-stats:0.7@hpi'
getplugins 'org.jenkins-ci.plugins:cloudbees-folder:6.0.2@hpi'
getplugins 'org.jenkins-ci.plugins:cobertura:1.9.8@hpi'
getplugins 'org.jenkins-ci.plugins:console-column-plugin:1.5@hpi'
getplugins 'org.jenkins-ci.plugins:covcomplplot:1.1.1@hpi'
getplugins 'org.jenkins-ci.plugins:credentials-binding:1.10@hpi'
getplugins 'org.jenkins-ci.plugins:credentials:2.1.13@hpi'
getplugins 'org.jenkins-ci.plugins:cvs:2.13@hpi'
getplugins 'org.jenkins-ci.plugins:dashboard-view:2.9.10@hpi'
getplugins 'org.jenkins-ci.plugins:display-url-api:1.1.1@hpi'
getplugins 'org.jenkins-ci.plugins:docker-commons:1.6@hpi'
getplugins 'org.jenkins-ci.plugins:docker-workflow:1.10@hpi'
getplugins 'org.jenkins-ci.plugins:durable-task:1.13@hpi'
getplugins 'org.jenkins-ci.plugins:embeddable-build-status:1.9@hpi'
getplugins 'org.jenkins-ci.plugins:external-monitor-job:1.7@hpi'
getplugins 'org.jenkins-ci.plugins:git-client:2.3.0@hpi'
getplugins 'org.jenkins-ci.plugins:git-server:1.7@hpi'
getplugins 'org.jenkins-ci.plugins:git:3.1.0@hpi'
getplugins 'org.jenkins-ci.plugins:github-api:1.85@hpi'
getplugins 'org.jenkins-ci.plugins:github-oauth:0.25@hpi'
getplugins 'org.jenkins-ci.plugins:groovy:1.30@hpi'
getplugins 'org.jenkins-ci.plugins:javadoc:1.4@hpi'
getplugins 'org.jenkins-ci.plugins:job-dsl:1.58@hpi'
getplugins 'org.jenkins-ci.plugins:junit:1.20@hpi'
getplugins 'org.jenkins-ci.plugins:ldap:1.14@hpi'
getplugins 'org.jenkins-ci.plugins:mailer:1.19@hpi'
getplugins 'org.jenkins-ci.plugins:mapdb-api:1.0.9.0@hpi'
getplugins 'org.jenkins-ci.plugins:matrix-auth:1.4@hpi'
getplugins 'org.jenkins-ci.plugins:matrix-project:1.8@hpi'
getplugins 'org.jenkins-ci.plugins:pam-auth:1.3@hpi'
getplugins 'org.jenkins-ci.plugins:pipeline-build-step:2.4@hpi'
getplugins 'org.jenkins-ci.plugins:pipeline-graph-analysis:1.3@hpi'
getplugins 'org.jenkins-ci.plugins:pipeline-input-step:2.5@hpi'
getplugins 'org.jenkins-ci.plugins:pipeline-milestone-step:1.3@hpi'
getplugins 'org.jenkins-ci.plugins:pipeline-stage-step:2.2@hpi'
getplugins 'org.jenkins-ci.plugins:plain-credentials:1.4@hpi'
getplugins 'org.jenkins-ci.plugins:rich-text-publisher-plugin:1.3@hpi'
getplugins 'org.jenkins-ci.plugins:scm-api:2.1.0@hpi'
getplugins 'org.jenkins-ci.plugins:script-security:1.27@hpi'
getplugins 'org.jenkins-ci.plugins:ssh-credentials:1.13@hpi'
getplugins 'org.jenkins-ci.plugins:ssh-slaves:1.13@hpi'
getplugins 'org.jenkins-ci.plugins:structs:1.6@hpi'
getplugins 'org.jenkins-ci.plugins:subversion:2.7.2@hpi'
getplugins 'org.jenkins-ci.plugins:token-macro:2.0@hpi'
getplugins 'org.jenkins-ci.plugins:translation:1.15@hpi'
getplugins 'org.jenkins-ci.plugins:view-job-filters:1.27@hpi'
getplugins 'org.jenkins-ci.plugins:windows-slaves:1.2@hpi'
getplugins 'org.jenkins-ci.ui:ace-editor:1.1@hpi'
getplugins 'org.jenkins-ci.ui:handlebars:1.1.1@hpi'
getplugins 'org.jenkins-ci.ui:jquery-detached:1.2.1@hpi'
getplugins 'org.jenkins-ci.ui:momentjs:1.1.1@hpi'
getplugins 'org.jenkinsci.plugins:pipeline-model-api:1.0.2@hpi'
getplugins 'org.jenkinsci.plugins:pipeline-model-declarative-agent:1.0.2@hpi'
getplugins 'org.jenkinsci.plugins:pipeline-model-definition:1.0.2@hpi'
getplugins 'org.jenkinsci.plugins:pipeline-stage-tags-metadata:1.0.2@hpi'
}
//download and copy specific versions of plugins
task getplugins(type: Copy) {
into "${pluginsDest}/plugins"
from configurations.getplugins
include '*.hpi'
rename '(.*)-[.0-9]+.hpi$', '$1.jpi'
}
//download and copy a specific version of Jenkins
task getjenkins(type: Copy) {
//println configurations.getjenkins
into jenkinsDest
from configurations.getjenkins
include '*.war'
rename '.*', 'jenkins.war'
}
//http://www.gradle.org/docs/current/userguide/gradle_wrapper.html
//generate gradlew with: gradle wrapper
task wrapper(type: Wrapper) {
gradleVersion = '2.13'
}
//Operating System packages
//I want to package the exact version of Jenkins plus all exact versions of plugins together
task filterPackagingScripts(type: Copy) {
from "${rootProject.projectDir}/packaging"
into "${buildDir}/packaging-filtered"
include '**/*.in'
filter(ReplaceTokens, beginToken: '@@', endToken: '@@', tokens: tokens)
filter(ReplaceTokens, beginToken: '~~', endToken: '~~', tokens: tokens)
rename '(.*).in', '$1'
}
task createManifest << {
configurations.all.findAll { !it.allDependencies.empty }.each { c ->
File file = new File("${buildDir}/${tokens['MANIFEST']}")
c.allDependencies.each { dep ->
file << ("${dep.group}:${dep.name}:${dep.version}\n")
}
}
}
createManifest.mustRunAfter filterPackagingScripts
ospackage {
packageName tokens['PACKAGENAME']
packager tokens['AUTHOR']
release '0'
url tokens['HOMEPAGE']
into tokens['PREFIX']
license tokens['LICENSE']
//shared package name dependencies
requires 'coreutils'
requires 'grep'
requires 'logrotate'
requires 'procps'
requires 'rsync'
//only sign if properties exist
if(project.hasProperty('signing.keyId') && project.hasProperty('signing.password') && project.hasProperty('signing.secretKeyRingFile')) {
signingKeyId project.getProperty('signing.keyId')
signingKeyPassphrase project.getProperty('signing.password')
signingKeyRingFile file(project.getProperty('signing.secretKeyRingFile'))
}
addParentDirs = true
preInstall = file("${buildDir}/packaging-filtered/preInstall.sh")
postInstall = file("${buildDir}/packaging-filtered/postInstall.sh")
preUninstall = file("${buildDir}/packaging-filtered/preUninstall.sh")
postUninstall = file("${buildDir}/packaging-filtered/postUninstall.sh")
from(configurations.getjenkins) {
into "lib/${tokens['ARTIFACTNAME']}"
rename '.*', "${tokens['ARTIFACTNAME']}.war"
user tokens['USER']
permissionGroup tokens['USER']
}
from(configurations.getplugins) {
into "lib/${tokens['ARTIFACTNAME']}/plugins"
include '*.hpi'
rename '(.*)-[.0-9]+.hpi$', '$1.jpi'
user tokens['USER']
permissionGroup tokens['USER']
}
from('scripts') {
into "lib/${tokens['ARTIFACTNAME']}/scripts"
user tokens['USER']
permissionGroup tokens['USER']
}
from(tokens['LICENSE_FILE']) {
into "lib/${tokens['ARTIFACTNAME']}"
fileType LICENSE
rename '.*', 'LICENSE'
user tokens['USER']
permissionGroup tokens['USER']
}
from('packaging/common/gitignore') {
into "lib/${tokens['ARTIFACTNAME']}"
user tokens['USER']
permissionGroup tokens['USER']
}
from("${buildDir}/${tokens['MANIFEST']}") {
into "lib/${tokens['ARTIFACTNAME']}"
user tokens['USER']
permissionGroup tokens['USER']
}
from("${buildDir}/packaging-filtered/share") {
into "lib/${tokens['ARTIFACTNAME']}/share"
user tokens['USER']
permissionGroup tokens['USER']
}
from("${buildDir}/packaging-filtered/jenkins.logrotate") {
into '/etc/logrotate.d'
fileMode 0644
fileType CONFIG
rename '.*', tokens['ARTIFACTNAME']
}
from("${buildDir}/packaging-filtered/jenkins.cron") {
into '/etc/cron.daily'
fileMode 0755
fileType CONFIG
rename '.*', tokens['ARTIFACTNAME']
}
}
buildRpm {
packageGroup 'Development/Tools/Building'
user 'root'
permissionGroup 'root'
type BINARY
os LINUX
addParentDirs = false
prefix tokens['PREFIX']
//how this package relates to other system packages
obsoletes 'jenkins'
obsoletes 'hudson'
requires 'cronie'
requires 'glibc-common'
from("${buildDir}/packaging-filtered/rpm/jenkins.init") {
into '/etc/init.d'
fileMode 0755
fileType CONFIG
rename '.*', tokens['ARTIFACTNAME']
}
from("${buildDir}/packaging-filtered/rpm/jenkins.sysconfig") {
addParentDirs = false
into '/etc/sysconfig'
fileMode 0600
fileType CONFIG | NOREPLACE
rename '.*', tokens['ARTIFACTNAME']
user tokens['USER']
permissionGroup tokens['USER']
}
}
buildRpm.dependsOn createManifest, filterPackagingScripts
buildDeb {
//packager is limited to only 32 chars for DEB files so only include email
packager tokens['AUTHOR'].replaceAll(/[^<]+<([^>]+)>/, '$1')
maintainer tokens['AUTHOR'].replaceAll(/[^<]+<([^>]+)>/, '$1')
packageGroup 'devel'
user 'root'
permissionGroup 'root'
priority 'extra'
requires 'adduser'
requires 'daemon'
requires 'net-tools'
requires 'psmisc'
requires('default-jre-headless', '2:1.7', Flags.GREATER | Flags.EQUAL).or('java7-runtime-headless').or('openjdk-8-jdk')
conflicts 'hudson'
conflicts 'jenkins'
replaces 'hudson'
replaces 'jenkins'
from("${buildDir}/packaging-filtered/deb/jenkins.init") {
into '/etc/init.d'
fileMode 0755
fileType CONFIG
rename '.*', tokens['ARTIFACTNAME']
}
from("${buildDir}/packaging-filtered/deb/jenkins.default") {
addParentDirs = false
into '/etc/default'
fileMode 0600
fileType CONFIG | NOREPLACE
rename '.*', tokens['ARTIFACTNAME']
user tokens['USER']
permissionGroup tokens['USER']
}
}
buildDeb.dependsOn createManifest, filterPackagingScripts
//packages task to create all system packages
task packages
packages.dependsOn buildRpm, buildDeb