This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathJenkinsfile
160 lines (145 loc) · 4.22 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
pipeline {
agent {
kubernetes {
inheritFrom 'centos-8'
}
}
parameters {
// see https://wiki.eclipse.org/Jenkins#JDK
choice(name: 'JDK_VERSION', description: 'Which JDK should be used?', choices: [
'temurin-jdk11-latest', 'temurin-jdk17-latest'
])
}
options {
buildDiscarder(logRotator(numToKeepStr:'15'))
disableConcurrentBuilds()
timeout(time: 90, unit: 'MINUTES')
}
triggers {
githubPush()
}
tools {
maven "apache-maven-3.8.6"
jdk "${params.JDK_VERSION}"
}
stages {
stage('Initialize') {
steps {
script {
properties([
[$class: 'GithubProjectProperty', displayName: '', projectUrlStr: 'https://github.com/eclipse/xtext-core/'],
[$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false]
])
currentBuild.displayName = String.format("#%s(%s)", BUILD_NUMBER, javaVersion("${params.JDK_VERSION}"))
}
sh '''
if [ -d ".git" ]; then
git reset --hard
fi
'''
dir('build') { deleteDir() }
dir('.m2/repository/org/eclipse/xtext') { deleteDir() }
dir('.m2/repository/org/eclipse/xtend') { deleteDir() }
sh '''
sed_inplace() {
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "$@"
else
sed -i "$@"
fi
}
targetfiles="$(find releng -type f -iname '*.target')"
for targetfile in $targetfiles
do
echo "Redirecting target platforms in $targetfile to $JENKINS_URL"
sed_inplace "s?<repository location=\\".*/job/\\([^/]*\\)/job/\\([^/]*\\)/?<repository location=\\"$JENKINS_URL/job/\\1/job/\\2/?" $targetfile
done
'''
}
}
stage('Maven Build') {
steps {
sh '''
mvn \
-f releng \
--batch-mode \
--update-snapshots \
-fae \
-Dmaven.repo.local=$WORKSPACE/.m2/repository \
-Dtycho.disableP2Mirrors=true \
clean install
'''
}
}
}
post {
success {
archiveArtifacts artifacts: 'build/**'
script {
// For release builds trigger releng/sign-and-deploy
def RELEASE_TYPE = getReleaseType ()
if (RELEASE_TYPE != "Integration" ) {
build job: 'releng/sign-and-deploy',
parameters: [
string(name: 'RELEASE_TYPE', value: "${RELEASE_TYPE}"),
string(name: 'BRANCH_TO_DEPLOY', value: "${env.BRANCH_NAME}")
],
wait: false
}
}
}
failure {
archiveArtifacts artifacts: '**/target/work/data/.metadata/.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'
}
slackSend (
message: "${lastResult} => ${curResult}: <${env.BUILD_URL}|${env.JOB_NAME}#${env.BUILD_NUMBER}>",
botUser: true,
channel: 'xtext-builds',
color: "${color}"
)
}
}
}
}
}
/**
* Determine the RELEASE_TYPE argument for downstream job releng/sign-and-deploy depending on current branch.
*/
def getReleaseType () {
if (env.BRANCH_NAME.startsWith("release_")) {
return "GA"
} else if (env.BRANCH_NAME.startsWith("milestone_")) {
return env.BRANCH_NAME.substring(env.BRANCH_NAME.lastIndexOf('.')+1)
} else {
return "Integration"
}
}
def javaVersion(String version) {
if (!version.contains('-jdk')) {
return 'jdk15'
} else {
return version.replaceAll(".*-(jdk\\d+).*", "\$1")
}
}