forked from eclipse-xtext/xtext
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
184 lines (165 loc) · 5.88 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
pipeline {
agent {
kubernetes {
inheritFrom 'ubuntu-2404-6gb'
}
}
parameters {
choice(name: 'TARGET_PLATFORM', choices: ['r202403', 'r202406', 'r202409', 'r202412', 'latest'], description: 'Which Target Platform should be used?')
// see https://wiki.eclipse.org/Jenkins#JDK
choice(name: 'JDK_VERSION', choices: [ '17', '21' ], description: 'Which JDK version should be used?')
}
triggers {
parameterizedCron(env.BRANCH_NAME == 'main' ? '''
H H(0-1) * * * %TARGET_PLATFORM=r202403;JDK_VERSION=17
H H(3-4) * * * %TARGET_PLATFORM=latest;JDK_VERSION=21
''' : '')
}
options {
buildDiscarder(logRotator(numToKeepStr:'10'))
disableConcurrentBuilds()
timeout(time: 360, unit: 'MINUTES')
}
tools {
// the Java version we use to run the build
// we force the effective JDK version for compilation/testing through Maven toolchains
jdk "temurin-jdk21-latest"
}
stages {
stage('Initialize') {
steps {
checkout scm
script {
currentBuild.displayName = String.format("#%s(JDK%s,Eclipse%s)", BUILD_NUMBER, javaVersion(), eclipseVersion())
}
sh '''
if [ -f "/sys/fs/cgroup/memory/memory.limit_in_bytes" ]; then
echo "Available memory: $(cat /sys/fs/cgroup/memory/memory.limit_in_bytes | numfmt --to iec --format '%f')"
fi
sed_inplace() {
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "$@"
else
sed -i "$@"
fi
}
'''
}
}
stage('Maven/Tycho Build & Test') {
environment {
MAVEN_OPTS = "-Xmx1500m"
// set all Java versions needed by our toolchains.xml
JAVA_HOME_17_X64 = tool(type:'jdk', name:'temurin-jdk17-latest')
JAVA_HOME_21_X64 = tool(type:'jdk', name:'temurin-jdk21-latest')
}
steps {
xvnc(useXauthority: true) {
sh """
./full-build.sh --tp=${selectedTargetPlatform()} \
${javaVersion() == 17 ? '--toolchains releng/toolchains.xml -Pstrict-jdk-17' : ''} \
${javaVersion() == 21 ? '-Pstrict-jdk-21' : ''}
"""
}
}// END steps
} // END stage
stage('Trigger Snapshot Deployment') {
when {
allOf {
expression {
currentBuild.getBuildCauses().toString().contains('Push event to branch')
}
branch 'main'
}
}
steps {
build job: "xtext-monorepo-full-deploy-nightly", wait: false
}
}
} // END stages
post {
always {
junit testResults: '**/target/surefire-reports/*.xml'
}
success {
archiveArtifacts artifacts: 'build/**, **/target/work/data/.metadata/.log, **/target/work/data/.metadata/bak*.log'
}
unsuccessful {
archiveArtifacts artifacts: 'org.eclipse.xtend.ide.swtbot.tests/screenshots/**, **/target/work/data/.metadata/.log, **/target/work/data/.metadata/bak*.log, **/hs_err_pid*.log'
}
cleanup {
script {
def curResult = currentBuild.currentResult
def lastResult = 'NEW'
if (currentBuild.previousBuild != null) {
lastResult = currentBuild.previousBuild.result
}
if (curResult != 'SUCCESS' || lastResult != 'SUCCESS') {
def color = ''
switch (curResult) {
case 'SUCCESS':
color = '#00FF00'
break
case 'UNSTABLE':
color = '#FFFF00'
break
case 'FAILURE':
color = '#FF0000'
break
default: // e.g. ABORTED
color = '#666666'
}
matrixSendMessage https: true,
hostname: 'matrix.eclipse.org',
accessTokenCredentialsId: "matrix-token",
roomId: '!zbliqcdqsggOFDCUoF:matrix.eclipse.org',
body: "${lastResult} => ${curResult} ${env.BUILD_URL} | ${env.JOB_NAME}#${env.BUILD_NUMBER}",
formattedBody: "<div><font color='${color}'>${lastResult} => ${curResult}</font> | <a href='${env.BUILD_URL}' target='_blank'>${env.JOB_NAME}#${env.BUILD_NUMBER}</a></div>"
}
}
}
}
}
/** return the Java version as Integer (8, 11, ...) */
def javaVersion() {
return Integer.parseInt(params.JDK_VERSION)
}
/** returns true when this build was triggered by an upstream build */
def isTriggeredByUpstream() {
return !"[]".equals(currentBuild.getBuildCauses('org.jenkinsci.plugins.workflow.support.steps.build.BuildUpstreamCause').toString())
}
/**
* Returns the Eclipse version dependent on the selected target platform.
* Result: '4.XX'
*/
def eclipseVersion() {
def targetPlatform = selectedTargetPlatform()
if (targetPlatform == 'latest') {
return "4.35"
} else {
def baseDate = java.time.LocalDate.parse("2018-06-01") // 4.8 Photon
def df = java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd")
def targetDate = java.time.LocalDate.parse(targetPlatform.substring(1)+"01", df)
long monthsBetween = java.time.temporal.ChronoUnit.MONTHS.between(baseDate, targetDate);
return "4."+ (8+(monthsBetween/3))
}
}
/**
* The target platform is primarily defined by the build parameter TARGET_PLATFORM.
* But when the build is triggered by upstream with at least Java version 21, 'latest'
* is returned.
*/
def selectedTargetPlatform() {
def tp = params.TARGET_PLATFORM
def isUpstream = isTriggeredByUpstream()
def javaVersion = javaVersion()
if (isTriggeredByUpstream() && javaVersion>=21) {
println("Choosing 'latest' target since this build was triggered by upstream with Java ${javaVersion}")
return 'latest'
} else if (isTriggeredByUpstream() && javaVersion>=17) {
println("Choosing 'r2024-03' target since this build was triggered by upstream with Java ${javaVersion}")
return 'r2024-03'
} else {
return tp
}
}