-
Notifications
You must be signed in to change notification settings - Fork 154
/
Jenkinsfile
170 lines (153 loc) · 5.21 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
config = [
agentLabel: '',
maven: 'Maven 3',
jdk: 'Zulu 17',
extraMavenArguments: '-U -Ddkpro.core.testCachePath="${WORKSPACE}/cache/dkpro-core-datasets" -Dmaven.artifact.threads=15 -T 4',
wipeWorkspaceBeforeBuild: true,
wipeWorkspaceAfterBuild: true
]
pipeline {
parameters {
string(
name: 'extraMavenArguments',
defaultValue: config.extraMavenArguments,
description: "Extra arguments to be passed to Maven (for testing; overrides only current build)")
string(
name: 'agentLabel',
defaultValue: config.agentLabel,
description: "Eligible agents (in case a build keeps running on a broken agent; overrides only current build)")
booleanParam(
name: 'wipeWorkspaceBeforeBuild',
defaultValue: config.wipeWorkspaceBeforeBuild,
description: "Wipe workspace before build (for testing; next build only)")
booleanParam(
name: 'wipeWorkspaceAfterBuild',
defaultValue: config.wipeWorkspaceAfterBuild,
description: "Wipe workspace after build (for testing; next build only)")
}
agent {
label params.agentLabel
}
tools {
maven config.maven
jdk config.jdk
}
options {
buildDiscarder(logRotator(
numToKeepStr: '25',
artifactNumToKeepStr: '5'
))
skipDefaultCheckout()
}
stages {
stage("Checkout code") {
steps {
script {
if (params.wipeWorkspaceBeforeBuild) {
echo "Wiping workspace..."
cleanWs(cleanWhenNotBuilt: true,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true)
}
}
dir('checkout') {
checkout scm
}
}
}
// Display information about the build environment. This can be useful for debugging
// build issues.
stage("Info") {
steps {
echo '=== Environment variables ==='
script {
if (isUnix()) {
sh 'printenv'
}
else {
bat 'set'
}
}
}
}
// Perform a merge request build. This is a conditional stage executed with the GitLab
// sources plugin triggers a build for a merge request. To avoid conflicts with other
// builds, this stage should not deploy artifacts to the Maven repository server and
// also not install them locally.
stage("PR build") {
when { branch 'PR-*' }
steps {
script {
currentBuild.description = 'Triggered by: <a href="' + CHANGE_URL + '">' + BRANCH_NAME +
': ' + env.CHANGE_BRANCH + '</a> (' + env.CHANGE_AUTHOR_DISPLAY_NAME + ')'
}
dir('checkout') {
withMaven(maven: config.maven, jdk: config.jdk, mavenLocalRepo: "$WORKSPACE/.repository") {
script {
def mavenCommand = 'mvn ' +
params.extraMavenArguments +
' -B -Dmaven.test.failure.ignore=true -T 4 -Pjacoco clean verify javadoc:javadoc';
if (isUnix()) {
sh script: mavenCommand
}
else {
bat script: mavenCommand
}
}
}
script {
def mavenConsoleIssues = scanForIssues tool: mavenConsole()
def javaIssues = scanForIssues tool: java()
def javaDocIssues = scanForIssues tool: javaDoc()
publishIssues id: "analysis", issues: [mavenConsoleIssues, javaIssues, javaDocIssues]
}
}
}
}
// Perform a SNAPSHOT build of a main branch. This stage is typically executed after a
// merge request has been merged. On success, it deploys the generated artifacts to the
// Maven repository server.
stage("SNAPSHOT build") {
when { branch pattern: "main|release/.*", comparator: "REGEXP" }
steps {
dir('checkout') {
withMaven(maven: config.maven, jdk: config.jdk, mavenLocalRepo: "$WORKSPACE/.repository") {
script {
def mavenCommand = 'mvn ' +
params.extraMavenArguments +
' -B -Dmaven.test.failure.ignore=true -Pjacoco clean verify javadoc:javadoc'
if (isUnix()) {
sh script: mavenCommand
}
else {
bat script: mavenCommand
}
}
}
script {
def mavenConsoleIssues = scanForIssues tool: mavenConsole()
def javaIssues = scanForIssues tool: java()
def javaDocIssues = scanForIssues tool: javaDoc()
def spotBugsIssues = scanForIssues tool: spotBugs()
def taskScannerIssues = scanForIssues tool: taskScanner()
publishIssues id: "analysis", issues: [mavenConsoleIssues, javaIssues, javaDocIssues, spotBugsIssues, taskScannerIssues]
}
}
}
}
}
post {
always {
script {
if (params.wipeWorkspaceAfterBuild) {
echo "Wiping workspace..."
cleanWs(cleanWhenNotBuilt: false,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true)
}
}
}
}
}