-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathbuild.gradle
235 lines (204 loc) · 8.27 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
plugins {
id "com.jfrog.artifactory" version "4.33.1"
}
apply plugin: 'groovy'
apply plugin: 'maven-publish'
project.ext {
jobDslVersion = '1.88'
jenkinsCoreVersion = '2.440.3'
jenkinsTestHarnessVersion = '2193.v71b_f09ec6d46'
testDependenciesOutputDirectory = new File(sourceSets.test.output.resourcesDir, 'test-dependencies')
artifactoryUri = System.getenv("ARTIFACTORY_URI")
publishingRepoKey = getArtifactoryRepoKey()
publishingRepoUsername = System.getenv("PUBLISHING_REPO_USERNAME")
publishingRepoPassword = System.getenv("PUBLISHING_REPO_PASSWORD")
}
configurations {
testPlugins {}
// see JENKINS-45512
testCompile {
exclude group: 'xalan'
exclude group: 'xerces'
}
}
sourceSets {
test {
resources {
srcDirs = ['src/test/resources', sourceSets.test.output.resourcesDir]
}
}
}
repositories {
if (artifactoryUri) {
maven { url "${artifactoryUri}/hmrc-releases" }
maven { url "${artifactoryUri}/hmrc-snapshots" }
maven { url "${artifactoryUri}/third-party-maven-releases" }
maven { url 'https://repo.jenkins-ci.org/public/' }
maven { url "${artifactoryUri}/jenkins-ci-releases/" }
maven { url "https://open.artefacts.tax.service.gov.uk/maven2/" }
} else {
maven { url 'https://repo.jenkins-ci.org/public/' }
maven { url 'https://repo.jenkins-ci.org/releases/' }
}
mavenLocal()
mavenCentral()
}
dependencies {
implementation 'org.codehaus.groovy:groovy-all:2.5.+'
implementation ('com.google.guava:guava:11.0.1') {
exclude module: 'jsr305'
}
implementation ("org.jenkins-ci.plugins:job-dsl-core:${jobDslVersion}") {
exclude module: 'ivy'
exclude module: 'xstream'
}
testImplementation 'org.spockframework:spock-junit4:2.3-groovy-2.5'
/**
* AbstractJobSpec relies on JUnit 4 features such as @ClassRule in order
* to load the in-memory Jenkins instance. Whilst recent versions of
* jenkins-test-harness support Junit 5, via the @WithJenkins annotation,
* it would require a significant effort to refactor AbstractJobSpec to use
* the new annotation. Until we're ready to do that work we have pinned
* the JUnit platform to JUnit 4
*/
testImplementation("junit:junit:4.13.2")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.9.3")
// Jenkins test harness dependencies
testImplementation "org.jenkins-ci.main:jenkins-test-harness:${jenkinsTestHarnessVersion}"
testImplementation "org.jenkins-ci.main:jenkins-war:${jenkinsCoreVersion}"
// Job DSL plugin including plugin dependencies
testImplementation "org.jenkins-ci.plugins:job-dsl:${jobDslVersion}"
testImplementation "org.jenkins-ci.plugins:job-dsl:${jobDslVersion}@jar"
testImplementation 'org.jenkins-ci.plugins:structs:1.6@jar'
// plugins to install in test instance
testPlugins 'com.coravy.hudson.plugins.github:github:1.37.3'
testPlugins 'io.jenkins.plugins:caffeine-api:3.1.8-133.v17b_1ff2e0599'
testPlugins 'org.jenkins-ci.plugins:ansicolor:1.0.2'
testPlugins 'org.jenkins-ci.plugins:build-monitor-plugin:1.14-653.va_1c684a_30b_ff'
testPlugins 'org.jenkins-ci.plugins:build-timeout:1.28'
testPlugins 'org.jenkins-ci.plugins:build-user-vars-plugin:1.9'
testPlugins 'org.jenkins-ci.plugins:claim:516.v36293563731d'
testPlugins 'org.jenkins-ci.plugins:cloudbees-folder:6.848.ve3b_fd7839a_81'
testPlugins 'org.jenkins-ci.plugins:envinject:2.901.v0038b_6471582'
testPlugins 'org.jenkins-ci.plugins:git:5.2.0'
testPlugins 'org.jenkins-ci.plugins:htmlpublisher:1.32'
testPlugins 'org.jenkins-ci.plugins:junit:1240.vf9529b_881428'
testPlugins 'org.jenkins-ci.plugins:matrix-auth:3.1.6'
testPlugins 'org.jenkins-ci.plugins:matrix-project:789.v57a_725b_63c79'
testPlugins 'org.jenkins-ci.plugins:nodejs:1.6.1'
testPlugins 'org.jenkins-ci.plugins:Parameterized-Remote-Trigger:3.1.6.3'
testPlugins 'org.jenkins-ci.plugins:parameterized-trigger:2.45'
testPlugins 'org.jenkins-ci.plugins:postbuildscript:3.2.0-460.va_fda_0fa_26720'
testPlugins 'org.jenkins-ci.plugins:preSCMbuildstep:44.v6ef4fd97f56e'
testPlugins 'org.jenkins-ci.plugins:timestamper:1.26'
testPlugins 'org.jenkins-ci.plugins:throttle-concurrents:2.14'
testPlugins 'org.jenkins-ci.plugins:urltrigger:1.02'
testPlugins 'org.jvnet.hudson.plugins:postbuild-task:1.9'
testPlugins 'org.jenkins-ci.plugins:ws-cleanup:0.44'
testPlugins 'com.sonyericsson.hudson.plugins.rebuild:rebuild:332.va_1ee476d8f6d'
// Plugins which ideally we would install, but they cause other plugins to downgrade and tests to break
// testPlugins 'org.jenkins-ci.plugins:description-setter:1.10'
// testPlugins 'org.jenkins-ci.plugins:ghprb:1.42.2'
}
version = getReleaseVersion()
logger.quiet("Project version is: ${project.version}")
group = 'uk.gov.hmrc'
task resolveTestPlugins(type: Copy) {
from configurations.testPlugins
into testDependenciesOutputDirectory
include '*.hpi'
include '*.jpi'
mustRunAfter compileJava
}
task writePluginIndexFile(type: DefaultTask, dependsOn: resolveTestPlugins) {
doFirst {
def baseNames = resolveTestPlugins.source.collect {
it.name[0..it.name.lastIndexOf('.') - 1]
}.sort()
logger.info("Copied plugins for tests.")
new File(resolveTestPlugins.destinationDir, 'index').setText(baseNames.join('\n'), 'UTF-8')
logger.info("Created plugin index file.")
}
}
test {
dependsOn tasks.writePluginIndexFile
inputs.files sourceSets.test.groovy.srcDirs, sourceSets.test.output.resourcesDir
// set build directory for Jenkins test harness, JENKINS-26331
systemProperty 'buildDirectory', project.buildDir.absolutePath
}
// Apply generic configuration to all Test tasks.
tasks.withType(Test).configureEach {
useJUnitPlatform()
testLogging {
showStandardStreams true
}
}
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
archiveClassifier = 'sources'
}
task javadocJar(type: Jar) {
from javadoc
archiveClassifier = 'javadoc'
}
publishing {
publications {
jenkinsJobBuilders(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
}
}
}
artifactoryDeploy {
doFirst {
validatePublishingConfiguration()
}
}
artifactory {
contextUrl = project.artifactoryUri
publish {
repository {
repoKey = project.publishingRepoKey
username = project.publishingRepoUsername
password = project.publishingRepoPassword
}
defaults {
publications('jenkinsJobBuilders')
}
publishBuildInfo = false
publishArtifacts = true
publishPom = true
}
}
private validatePublishingConfiguration() {
boolean isReleaseVersion = isReleaseVersion()
final Set<String> requiredPublishingEnvVars = ["ARTIFACTORY_URI", "PUBLISHING_REPO_USERNAME", "PUBLISHING_REPO_PASSWORD"]
if(isReleaseVersion) {
requiredPublishingEnvVars << "RELEASES_PUBLISHING_REPO"
}
else {
requiredPublishingEnvVars << "SNAPSHOTS_PUBLISHING_REPO"
}
requiredPublishingEnvVars.each { envVar ->
if(!System.getenv(envVar)) {
throw new GradleException("Environment variable '${envVar}' is required to publish ${isReleaseVersion ? "releases" : "snapshots"} to Artifactory, but was not provided.")
}
}
}
private String getReleaseVersion() {
return project.hasProperty("releaseVersion") ? project.releaseVersion.replaceAll('release/', '') : 'unnumbered-development-build'
}
private boolean isReleaseVersion() {
final boolean isReleaseVersion = (getReleaseVersion() ==~ /^[0-9]+\.[0-9]+\.[0-9]+$/)
logger.quiet("Specified releaseVersion '${getReleaseVersion()}' has been identified as a ${isReleaseVersion ? "release" : "snapshot"} version.")
return isReleaseVersion
}
private String getArtifactoryRepoKey() {
final String repoKeyEnvVar = isReleaseVersion() ? "RELEASES_PUBLISHING_REPO" : "SNAPSHOTS_PUBLISHING_REPO"
final String repoKey = System.getenv(repoKeyEnvVar)
logger.quiet("Artifactory repo key is: ${repoKey}")
return repoKey
}
tasks.publish.dependsOn(build)
tasks.artifactoryPublish.dependsOn(check)