This repository has been archived by the owner on Oct 8, 2019. It is now read-only.
forked from things-and-stuff/jenkins-pipeline-dsl-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
137 lines (107 loc) · 3.67 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
import java.util.jar.JarFile
apply plugin: 'groovy'
sourceSets {
jobs {
groovy {
srcDirs 'jobs'
}
}
}
configurations {
jenkins
compile.extendsFrom(jenkins)
lib
compile.extendsFrom(lib)
}
repositories {
mavenLocal()
maven { url "https://jitpack.io" }
maven { url 'http://repo.jenkins-ci.org/releases/' }
jcenter()
mavenCentral()
}
ext {
jenkinsVersion = '1.609.2'
jobDslVersion = '1.37'
}
dependencies {
//TODO use a proper version once published
lib 'com.github.things-and-stuff:jenkins-pipeline-dsl:0a064df2b2'
lib 'org.yaml:snakeyaml:1.16'
jenkins "org.jenkins-ci.main:jenkins-core:${project.ext.jenkinsVersion}"
compile 'org.codehaus.groovy:groovy-all:2.4.4'
compile 'com.google.guava:guava:18.0'
compile "org.jenkins-ci.plugins:job-dsl:${project.ext.jobDslVersion}@jar"
compile "org.jenkins-ci.plugins:job-dsl-core:${project.ext.jobDslVersion}"
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude module: 'groovy-all'
}
testCompile 'xmlunit:xmlunit:1.6'
}
test {
testLogging {
exceptionFormat = 'full'
}
}
task cleanLibs(type: Delete) {
delete 'lib'
}
tasks.clean.dependsOn 'cleanLibs'
task libs(type: Copy) {
into 'lib'
from configurations.lib
}
if (project.hasProperty('local')) {
configurations {
jenkinsWar
jenkinsPlugins
compile.extendsFrom(jenkinsWar, jenkinsPlugins)
}
dependencies {
jenkinsWar (group: 'org.jenkins-ci.main', name: 'jenkins-war', version: project.ext.jenkinsVersion, ext: 'war')
}
apply from: 'plugins.gradle'
def jenkinsHome = new File(System.getProperty('user.home'), "${project.name}_jenkins_home")
if (project.hasProperty('localJenkinsHome')) {
jenkinsHome = new File(project.ext.localJenkinsHome)
}
def pluginsDir = new File(jenkinsHome, 'plugins/')
task copyJenkinsBaseConfig << {
// GFileUtils.copyFile(new File('./jenkins-bootstrap/'), jenkinsHome.absoluteFile)
}
task runJenkins << {
// copied from gradle-jpi-plugin
// create new configuration with plugin dependencies, ignoring the (jar) extension to get the HPI/JPI files
//TODO come up with a better way to start jenkins (that will not lock this gradle project)
Configuration plugins = project.configurations.create('plugins')
project.configurations.getByName('jenkinsPlugins').dependencies.each {
project.dependencies.add(plugins.name, "${it.group}:${it.name}:${it.version}")
}
// copy the resolved HPI/JPI files to the plugins directory
plugins.resolvedConfiguration.resolvedArtifacts.findAll { it.extension in ['hpi', 'jpi'] }.each {
GFileUtils.copyFile(it.file, new File(pluginsDir, "${it.name}.${it.extension}"))
}
// pin particular plugins
new File(pluginsDir.absolutePath + '/credentials.jpi.pinned').createNewFile()
System.setProperty('JENKINS_HOME', jenkinsHome.absolutePath)
System.setProperty('DSL_PROJECT_ROOT', project.projectDir.absolutePath)
def c = project.configurations.getByName('jenkinsWar')
def files = c.resolve()
def war = files[0]
def cl = new URLClassLoader([war.toURI().toURL()] as URL[])
def mainClass = new JarFile(war).manifest.mainAttributes.getValue('Main-Class')
cl.loadClass(mainClass).main()
Thread.currentThread().join()
}
runJenkins.dependsOn(copyJenkinsBaseConfig)
runJenkins.dependsOn(libs)
}
apply plugin: 'idea'
idea {
module {
excludeDirs += file('lib')
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.7'
}