-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
212 lines (196 loc) · 9.55 KB
/
Jenkinsfile
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
// Minor housekeeping logic
boolean shouldPublish = env.BRANCH_NAME.equals("master") || env.BRANCH_NAME.equals("develop")
String[] jobNameParts = env.JOB_NAME.tokenize('/') as String[]
String realProjectName = jobNameParts.length < 2 ? env.JOB_NAME : jobNameParts[jobNameParts.length - 2]
boolean originNanoware = jobNameParts[0].equals("Nanoware")
// referring to the experimental line of Nanoware module build jobs on jenkins (jenkins.terasology.io/teraorg/job/Nanoware/job/TerasologyModules/job/X)
boolean experimental = jobNameParts.length >= 2 && jobNameParts[2].startsWith("X")
// Vary where we copy the build harness from based on where the actively running job lives
String buildHarnessOrigin = "Terasology/engine/develop"
if (originNanoware) {
if (experimental) {
// Unusual module tests with separate build harness (and JteConfig branch - defined elsewhere)
buildHarnessOrigin = "Nanoware/Terasology/experimental"
} else {
// "Normal" module tests with the regular build harness in Nanoware land
buildHarnessOrigin = "Nanoware/Terasology/develop"
}
}
// Only keep a single build's worth of artifacts before truncating (module jars get published to Artifactory anyway)
properties([
buildDiscarder(logRotator(artifactNumToKeepStr: '1'))
])
/**
* Main pipeline definition for building Terasology modules.
*
* It uses the Declarative Pipeline Syntax.
* See https://www.jenkins.io/doc/book/pipeline/syntax
*
* This pipeline uses Jenkins plugins to collect and report additional information about the build.
*
* - Warnings Next Generation Plugin (https://plugins.jenkins.io/warnings-ng/)
* To record issues from code scans and static analysis tools, e.g., CheckStyle or Spotbugs.
* - Git Forensics Plugin (https://plugins.jenkins.io/git-forensics/)
* To compare code scans and static analysis against a reference build from the base branch.
* - JUnit Plugin (https://plugins.jenkins.io/junit/)
* To record the results of our test suites from JUnit format.
*
*/
pipeline {
agent {
label 'ts-module && heavy && java17'
}
stages {
// declarative pipeline does `checkout scm` automatically when hitting first stage
stage('Setup') {
steps {
echo 'Automatically checked out the things!'
// the default resolution when omitting `targetBranch` is to `master`
// this is wrong in our case, so explicitly set `develop` as default
// TODO: does this also work for PRs with different base branch?
discoverGitReferenceBuild(targetBranch: 'develop')
echo "Copying in the build harness from an engine job: $buildHarnessOrigin"
copyArtifacts(projectName: buildHarnessOrigin, filter: "templates/build.gradle, templates/module.logback-test.xml", flatten: true, selector: lastSuccessful())
copyArtifacts(projectName: buildHarnessOrigin, filter: "*, gradle/wrapper/**, config/**, natives/**, build-logic/**", selector: lastSuccessful())
echo "Setting project name to: $realProjectName"
writeFile file: 'settings.gradle',
text: """rootProject.name = '$realProjectName'; includeBuild('build-logic')"""
sh label: 'configure workspace', script: '''
rm -f gradle.properties
chmod a+x gradlew
mkdir -p src/test/resources
mv --verbose --no-clobber module.logback-test.xml src/test/resources/logback-test.xml
'''
sh './gradlew --version'
}
}
stage('Build') {
steps {
// Jenkins sometimes doesn't run Gradle automatically in plain console mode, so make it explicit
sh label: 'determining dependencies', script: './gradlew --console=plain clean htmlDependencyReport'
// Reporting this compile task as `stage/Build` for backwards compatibility with things configured
// to watch for CloudBees SCM Reporting stage status.
gitStatusWrapper(gitHubContext: 'stage/Build', description: 'Compiling Java') {
sh './gradlew --console=plain jar'
}
archiveArtifacts 'build/libs/*.jar'
}
post {
always {
recordIssues enabledForFailure: true, failOnError: true, publishAllIssues: true, skipBlames: true,
qualityGates: [[threshold: 1, type: 'TOTAL_ERROR', unstable: false]],
tools: [java()]
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'build/reports/project/dependencies',
reportFiles: 'index.html',
reportName: 'Dependency Report',
reportTitles: 'Dependency Report'
])
}
}
}
stage('Unit Tests') {
steps {
sh './gradlew --console=plain unitTest'
}
post {
always {
// Gradle generates both a HTML report of the unit tests to `build/reports/tests/*`
// and XML reports to `build/test-results/*`.
// We need to upload the XML reports for visualization in Jenkins.
//
// See https://docs.gradle.org/current/userguide/java_testing.html#test_reporting
junit testResults: '**/build/test-results/unitTest/*.xml', allowEmptyResults: true
// Jenkins truncates large test outputs, so archive it as well.
tar file: 'build/unitTest-results.tgz', archive: true, compress: true, overwrite: true,
glob: '**/build/test-results/unitTest/*.xml'
}
}
}
stage('Publish') {
when {
expression {
shouldPublish
}
}
steps {
withCredentials([usernamePassword(credentialsId: 'artifactory-gooey', \
usernameVariable: 'artifactoryUser', \
passwordVariable: 'artifactoryPass')]) {
sh '''./gradlew \\
--console=plain \\
-Dorg.gradle.internal.publish.checksums.insecure=true \\
publish \\
-PmavenUser=${artifactoryUser} \\
-PmavenPass=${artifactoryPass}
'''
}
}
}
stage('Analytics') {
steps {
sh './gradlew --console=plain check -x test --continue'
}
post {
always {
recordIssues skipBlames: true,
tools: [
checkStyle(pattern: '**/build/reports/checkstyle/*.xml'),
spotBugs(pattern: '**/build/reports/spotbugs/*.xml', useRankAsPriority: true),
pmdParser(pattern: '**/build/reports/pmd/*.xml')
]
recordIssues skipBlames: true,
tool: taskScanner(includePattern: '**/*.java,**/*.groovy,**/*.gradle', \
lowTags: 'WIBNIF', normalTags: 'TODO', highTags: 'FIXME')
}
}
}
stage('Documentation') {
steps {
sh './gradlew --console=plain javadoc'
script {
if (fileExists("build/docs/javadoc/index.html")) {
javadoc javadocDir: 'build/docs/javadoc', keepAll: false
recordIssues skipBlames: true, tool: javaDoc()
}
}
}
post {
always {
publishHTML([
allowMissing: true,
keepAll: false,
alwaysLinkToLastBuild: true,
reportDir: 'docs',
reportFiles: 'index.html',
reportName: 'Docs',
reportTitles: 'Docs'
])
}
}
}
stage('Integration Tests') {
steps {
warnError("Integration Tests Failed") { // if this errs, mark the build unstable, not failed.
sh './gradlew --console=plain integrationTest'
}
}
post {
always {
// Gradle generates both a HTML report of the unit tests to `build/reports/tests/*`
// and XML reports to `build/test-results/*`.
// We need to upload the XML reports for visualization in Jenkins.
//
// See https://docs.gradle.org/current/userguide/java_testing.html#test_reporting
junit testResults: '**/build/test-results/integrationTest/*.xml', allowEmptyResults: true, healthScaleFactor: 0.0
// Jenkins truncates large test outputs, so archive it as well.
tar file: 'build/integrationTest-results.tgz', archive: true, compress: true, overwrite: true,
glob: '**/build/test-results/integrationTest/*.xml'
}
}
}
}
}