forked from apache/incubator-kie-optaplanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
123 lines (116 loc) · 4.08 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
@Library('jenkins-pipeline-shared-libraries')_
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 {
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '10', numToKeepStr: '')
timeout(time: 120, unit: 'MINUTES')
}
environment {
MAVEN_OPTS = '-Xms1024m -Xmx4g'
}
stages {
stage('Initialize') {
steps {
script {
mailer.buildLogScriptPR()
checkoutRuntimesRepo()
checkoutRepo('optaplanner')
String quickstartsRepo = 'optaplanner-quickstarts'
dir(quickstartsRepo) {
// If the PR to OptaPlanner targets the 'master' branch, we assume the branch 'development' for quickstarts.
String quickstartsChangeTarget = changeTarget == 'master' ? 'development' : changeTarget
githubscm.checkoutIfExists(quickstartsRepo, changeAuthor, changeBranch, 'kiegroup', quickstartsChangeTarget, true)
}
}
}
}
stage('Build Kogito Runtimes skipping tests') {
steps {
mavenCleanInstall("kogito-runtimes", true, [])
}
}
stage('Build OptaPlanner') {
steps {
mavenCleanInstall('optaplanner', false, ['run-code-coverage'], '-Dfull')
}
}
stage('Analyze OptaPlanner by SonarCloud') {
steps {
withCredentials([string(credentialsId: 'SONARCLOUD_TOKEN', variable: 'SONARCLOUD_TOKEN')]) {
runMaven("validate", "optaplanner", true, ["sonarcloud-analysis"], "-e -nsu -Dsonar.projectKey=org.optaplanner:optaplanner")
}
}
}
stage('Build OptaPlanner Quickstarts') {
steps {
mavenCleanInstall("optaplanner-quickstarts", false, [])
}
}
}
post {
always {
sh '$WORKSPACE/trace.sh'
junit '**/target/surefire-reports/**/*.xml, **/target/failsafe-reports/**/*.xml'
cleanWs()
}
failure {
script {
mailer.sendEmail_failedPR()
}
}
unstable {
script {
mailer.sendEmail_unstablePR()
}
}
fixed {
script {
mailer.sendEmail_fixedPR()
}
}
}
}
void checkoutRepo(String repo, String dirName=repo) {
dir(dirName) {
githubscm.checkoutIfExists(repo, changeAuthor, changeBranch, 'kiegroup', changeTarget, true)
}
}
void checkoutRuntimesRepo() {
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('kogito-runtimes') {
githubscm.checkoutIfExists('kogito-runtimes', changeAuthor, changeBranch, 'kiegroup', targetBranch, true)
}
}
void mavenCleanInstall(String directory, boolean skipTests = false, List profiles = [], String extraArgs = "") {
runMaven("clean install", directory, skipTests, profiles, extraArgs)
}
void runMaven(String command, String directory, boolean skipTests = false, List profiles = [], String extraArgs = "") {
mvnCmd = command
if(profiles.size() > 0){
mvnCmd += " -P${profiles.join(',')}"
}
if(extraArgs != ""){
mvnCmd += " ${extraArgs}"
}
dir(directory) {
maven.runMavenWithSubmarineSettings(mvnCmd, skipTests)
}
}