-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.gradle
165 lines (142 loc) · 4.84 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
import com.mkobit.jenkins.pipelines.http.ApiTokenAuthentication
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
plugins {
id 'com.mkobit.jenkins.pipelines.shared-library' version '0.10.1'
id 'java'
id 'groovy'
}
tasks {
wrapper {
gradleVersion = '8.12'
}
}
java {
sourceCompatibility = JavaVersion.VERSION_17
}
dependencies {
testImplementation(platform("org.junit:junit-bom:${junitVersion}"))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation("org.mockito:mockito-junit-jupiter:${mockitoVersion}")
}
test {
useJUnitPlatform()
}
// add jenkinsResources as resources folder as it contains idea.gdsl
def jenkinsResourcesFolder = 'jenkinsResources'
def pipelinesFolder = 'pipelines'
def allSrcDirs = [pipelinesFolder, jenkinsResourcesFolder, 'vars', 'src']
sourceSets {
main {
java {
srcDirs = [allSrcDirs]
exclude 'resources'
}
}
integrationTest {
java {
srcDirs = [allSrcDirs]
exclude 'resources'
}
}
}
if (project.hasProperty("jenkinsUrl") && project.hasProperty("jenkinsUser") && project.hasProperty("jenkinsApiToken")) {
jenkinsIntegration {
baseUrl.set(uri(project.property("jenkinsUrl")).toURL())
authentication.set(providers.provider { new ApiTokenAuthentication(project.property("jenkinsUser").toString(), project.property("jenkinsApiToken").toString()) })
downloadDirectory.set(layout.projectDirectory.dir(jenkinsResourcesFolder))
}
}
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 JsonSlurper().parse(dependenciesFile)
contents.dependencies.each { dep ->
sharedLibrary {
pluginDependencies {
dependency(dep.group, dep.name, dep.version)
}
}
}
}
tasks.register('syncJenkinsConfig') {}
tasks.register('collectPluginDependencies') {
doLast {
// Excluded plugins (empty by default)
//def exludes = ["jobConfigHistory", "metrics", "ec2"] as Set
def excludedPlugins = [] as Set
def pluginsFile = file("${jenkinsResourcesFolder}/plugins.json")
def dependencies = []
def notResolvedPlugins = []
if (pluginsFile.exists()) {
def contents = new JsonSlurper().parse(pluginsFile)
contents.plugins.each { plugin ->
if (excludedPlugins.contains(plugin.shortName)) {
logger.lifecycle("Plugin '${plugin.shortName}' is skipped")
} else if (plugin.active && plugin.enabled) {
def groups = [
"io.jenkins.plugins",
"org.jenkinsci.plugins",
"org.jenkins-ci",
"org.jenkins-ci.main",
"org.jenkins-ci.lib",
"org.jenkins-ci.modules",
"org.jenkins-ci.plugins",
"org.jenkins-ci.plugins.workflow",
"org.jenkins-ci.plugins.aws-java-sdk",
"org.jenkins-ci.plugins.pipeline-stage-view",
"jp.ikedam.jenkins.plugins",
"io.jenkins.blueocean"
]
// Find the first group where the dependency resolves
def resolved = groups.find { group ->
def dependency = resolveDependency(group, plugin.shortName, plugin.version)
if (dependency) {
dependencies.add([group: group, name: plugin.shortName, version: plugin.version])
logger.lifecycle("Dependency '${dependency}' found")
return true
}
return false
}
// If no resolution was found, add to skipped plugins
if (!resolved) {
notResolvedPlugins.add(plugin.shortName)
}
} else {
logger.lifecycle("Plugin '${plugin.shortName}' is disabled")
}
}
logger.lifecycle("Not resolved plugins: ${notResolvedPlugins.join(', ')}")
// Create or overwrite the output file
def output = file("${jenkinsResourcesFolder}/dependencies.json")
if (output.exists()) {
output.delete()
}
output.createNewFile()
output << JsonOutput.prettyPrint(JsonOutput.toJson([dependencies: dependencies]))
} else {
logger.warn("Plugins file '${pluginsFile}' does not exist.")
}
}
}
tasks.named('syncJenkinsConfig'){
dependsOn retrieveJenkinsVersion, retrieveJenkinsGdsl, collectPluginDependencies
}
def resolveDependency(String group, String shortName, String version) {
try {
def dependency = "${group}:${shortName}:${version}"
def testConfig = project.configurations.create("testConfig-${UUID.randomUUID()}")
testConfig.setCanBeResolved(true)
project.dependencies."${testConfig.name}" dependency
testConfig.resolve()
return dependency
} catch (ignored) {
return null
}
}