-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.gradle
109 lines (96 loc) · 3.96 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
plugins {
id "com.mkobit.jenkins.pipelines.shared-library" version "0.10.1"
}
// add jenkinsResources as resources folder as it contains idea.gdsl
def jenkinsResourcesFolder = "jenkinsResources"
def pipelinesFolder = "pipelines"
sourceSets {
main {
java {
srcDir(pipelinesFolder)
}
}
integrationTest {
java {
srcDir(jenkinsResourcesFolder)
}
}
}
if (project.hasProperty("jenkinsUrl") && project.hasProperty("jenkinsUser") && project.hasProperty("jenkinsApiToken")) {
jenkinsIntegration {
baseUrl.set(uri(project.property("jenkinsUrl")).toURL())
authentication.set(providers.provider { new com.mkobit.jenkins.pipelines.http.ApiTokenAuthentication(project.property("jenkinsUser"), project.property("jenkinsApiToken")) })
downloadDirectory.set(layout.projectDirectory.dir(jenkinsResourcesFolder))
}
}
dependencies {
testImplementation(platform("org.junit:junit-bom:${junitVersion}"))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation("org.mockito:mockito-junit-jupiter:${mockitoVersion}")
}
test {
useJUnitPlatform()
}
def coreVersionFile = project.file("${jenkinsResourcesFolder}/core-version.txt")
if (coreVersionFile.exists()) {
def jenkinsVersion = coreVersionFile.text.trim()
sharedLibrary {
coreVersion = jenkinsVersion
}
}
def dependenciesFile = file("${jenkinsResourcesFolder}/dependecies.json")
if (dependenciesFile.exists()) {
def contents = new groovy.json.JsonSlurper().parse(dependenciesFile)
contents.dependencies.each { dep ->
sharedLibrary {
pluginDependencies {
dependency(dep.group, dep.name, dep.version)
}
}
}
}
task syncJenkinsConfig() {}
task collectPluginDependencies() {
doLast {
//def exludes = ["jobConfigHistory", "metrics", "ec2"] as Set
def exludes = [] as Set
def pluginsFile = file("${jenkinsResourcesFolder}/plugins.json")
def dependencies = []
if (pluginsFile.exists()) {
def contents = new groovy.json.JsonSlurper().parse(pluginsFile)
contents.plugins.each { plugin ->
if (exludes.contains(plugin.shortName)) {
println "Plugin '${plugin.shortName}' is skipped"
} else if (plugin.active && plugin.enabled) {
List<String> groups = ["org.jenkins-ci.plugins", "org.jenkinsci.plugins"]
for (String group : groups) {
def dependency = "${group}:${plugin.shortName}:${plugin.version}"
try {
Configuration testConfig = project.configurations.create("testConfig-${UUID.randomUUID().toString()}")
testConfig.setCanBeResolved(true)
project.dependencies."${testConfig.name}" dependency
testConfig.resolve()
dependencies.add(["group": group, "name": plugin.shortName, "version": plugin.version])
println "Dependency '${dependency}' found"
break
} catch (e) {
println "Dependency '${dependency}' not found"
}
}
} else {
println "Plugin '${plugin.shortName}' is disabled"
}
}
def output = file("${jenkinsResourcesFolder}/dependecies.json")
if (output.exists()) {
output.delete()
}
output.createNewFile()
output << groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(["dependencies": dependencies]))
}
}
}
syncJenkinsConfig.dependsOn retrieveJenkinsVersion
syncJenkinsConfig.dependsOn retrieveJenkinsPluginData
syncJenkinsConfig.dependsOn retrieveJenkinsGdsl
retrieveJenkinsPluginData.finalizedBy collectPluginDependencies