forked from apache/incubator-kie-kogito-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
191 lines (179 loc) · 5.66 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
@Library('jenkins-pipeline-shared-libraries')_
import org.kie.jenkins.MavenCommand
changeAuthor = env.ghprbPullAuthorLogin ?: CHANGE_AUTHOR
changeBranch = env.ghprbSourceBranch ?: CHANGE_BRANCH
changeTarget = env.ghprbTargetBranch ?: CHANGE_TARGET
pipeline {
agent {
label 'kie-rhel7 && kie-mem16g'
}
tools {
maven 'kie-maven-3.6.2'
jdk 'kie-jdk11'
}
options {
timestamps()
timeout(time: env.TIMEOUT_VALUE, unit: 'MINUTES')
}
environment {
MAVEN_OPTS = '-Xms1024m -Xmx4g'
SONARCLOUD_TOKEN = credentials('SONARCLOUD_TOKEN')
}
stages {
stage('Initialize') {
steps {
sh 'export XAUTHORITY=$HOME/.Xauthority'
sh 'chmod 600 $HOME/.vnc/passwd'
checkoutRepo('kogito-runtimes')
checkoutOptaplannerRepo()
checkoutRepo('kogito-apps')
}
}
stage('Build quarkus') {
when {
expression { return getQuarkusBranch() }
}
steps {
script {
checkoutQuarkusRepo()
getMavenCommand('quarkus', false)
.withProperty('quickly')
.run('clean install')
}
}
}
stage('Build Runtimes') {
steps {
script {
getMavenCommand('kogito-runtimes')
.skipTests(true)
.withProperty('skipITs', true)
.run('clean install')
}
}
}
stage('Build OptaPlanner') {
steps {
script {
getMavenCommand('optaplanner')
.withProperty('quickly')
.run('clean install')
}
}
}
stage('Build Apps') {
steps {
script {
mvnCmd = getMavenCommand('kogito-apps', true, true)
if (isNormalPRCheck()) {
mvnCmd.withProperty('validate-formatting')
.withProfiles(['run-code-coverage'])
}
mvnCmd.run('clean install')
}
}
post {
cleanup {
script {
cleanContainers()
}
}
}
}
stage('Analyze Apps by SonarCloud') {
when {
expression { isNormalPRCheck() }
}
steps {
script {
getMavenCommand('kogito-apps')
.withOptions(['-e', '-nsu'])
.withProfiles(['sonarcloud-analysis'])
.run('validate')
}
}
}
}
post {
always {
script {
archiveArtifacts artifacts: '**/target/*-runner.jar, **/target/*-runner', fingerprint: true
junit '**/**/junit.xml'
junit '**/target/surefire-reports/**/*.xml, **/target/failsafe-reports/**/*.xml'
}
}
failure {
script {
mailer.sendEmail_failedPR()
}
}
unstable {
script {
mailer.sendEmail_unstablePR()
}
}
fixed {
script {
mailer.sendEmail_fixedPR()
}
}
cleanup {
script {
util.cleanNode('docker')
}
}
}
}
void checkoutRepo(String repo, String dirName=repo) {
dir(dirName) {
githubscm.checkoutIfExists(repo, changeAuthor, changeBranch, 'kiegroup', changeTarget, true)
}
}
void checkoutQuarkusRepo() {
dir('quarkus') {
checkout(githubscm.resolveRepository('quarkus', 'quarkusio', getQuarkusBranch(), false))
}
}
void checkoutOptaplannerRepo() {
String targetBranch = changeTarget
String [] versionSplit = targetBranch.split("\\.")
if (versionSplit.length == 3
&& versionSplit[0].isNumber()
&& versionSplit[1].isNumber()
&& versionSplit[2] == 'x') {
targetBranch = "${Integer.parseInt(versionSplit[0]) + 7}.${versionSplit[1]}.x"
} else {
echo "Cannot parse changeTarget as release branch so going further with current value: ${changeTarget}"
}
dir('optaplanner') {
githubscm.checkoutIfExists('optaplanner', changeAuthor, changeBranch, 'kiegroup', targetBranch, true)
}
}
MavenCommand getMavenCommand(String directory, boolean addQuarkusVersion=true, boolean canNative = false) {
mvnCmd = new MavenCommand(this, ['-fae'])
.withSettingsXmlId('kogito_release_settings')
.withProperty('java.net.preferIPv4Stack', true)
.inDirectory(directory)
if (addQuarkusVersion && getQuarkusBranch()) {
mvnCmd.withProperty('version.io.quarkus', '999-SNAPSHOT')
}
if (canNative && isNative()) {
mvnCmd.withProfiles(['native'])
.withProperty('quarkus.native.container-build', true)
.withProperty('quarkus.native.container-runtime', 'docker')
.withProperty('quarkus.profile', 'native') // Added due to https://github.com/quarkusio/quarkus/issues/13341
}
return mvnCmd
}
void cleanContainers() {
cloud.cleanContainersAndImages('docker')
}
boolean isNative() {
return env['NATIVE'] && env['NATIVE'].toBoolean()
}
String getQuarkusBranch() {
return env['QUARKUS_BRANCH']
}
boolean isNormalPRCheck() {
return !(getQuarkusBranch() || isNative())
}