-
Notifications
You must be signed in to change notification settings - Fork 18
/
Jenkinsfile
288 lines (256 loc) · 11.3 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
pipeline {
agent {
label "ubuntu-2404"
}
parameters {
choice(name: 'RELEASE_TYPE', choices: ['Integration', 'Beta', 'M0', 'M1', 'M2', 'M3', 'M4', 'M5', 'RC1', 'RC2', 'GA'], description:
'''Kind of release to build. The chosen value is dependent on the parameter BUILD_TYPE. Use value:
<ul>
<li><tt>Integration</tt>: Continuous Build</li>
<li><tt>GA</tt>: Release Build</li>
<li>Any other: Stable/Milestone Build</tt></li>
</ul>''')
booleanParam(
name: 'FORCE_PUBLISH',
defaultValue: false,
description: 'Force publishing of build artifacts to Eclipse project storage & OSSRH?'
)
}
triggers {
parameterizedCron(env.BRANCH_NAME == 'master' ? '''H H(0-1) * * *''' : '')
}
options {
buildDiscarder(logRotator(numToKeepStr:'5'))
disableConcurrentBuilds()
timeout(time: 60, unit: 'MINUTES')
timestamps()
}
environment {
PROJECT_STORAGE_PATH = '/home/data/httpd/download.eclipse.org/modeling/emft/mwe'
DOWNLOAD_AREA = "$PROJECT_STORAGE_PATH/downloads/drops"
KEYRING = credentials('11ef2671-e2bc-4da7-8f89-f4b0ba8ffa3e')
SCRIPTS = "$WORKSPACE/git-repo/releng/jenkins/scripts"
RELEASE_TYPE="$params.RELEASE_TYPE"
FORCE_PUBLISH="$params.FORCE_PUBLISH"
}
stages {
stage('Prepare') {
steps {
dir ('git-repo') {
checkout scm
}
dir ('git-repo-nightly') {
checkout scm
}
sh '''
# Clean up the build result
rm -rf build-result/
mkdir -p build-result/downloads/
mkdir -p build-result/javadoc/
mkdir -p build-result/composite/
# call the versioning script when a release is built
# this will set the final release number for Maven artifacts according to RELEASE_TYPE
# and disable strict version checking by Tycho, so that p2 artifacts keep their qualifier
if [ "$RELEASE_TYPE" != "Integration" ]; then
pushd $(pwd) && cd git-repo
bash ./set_version.sh --release=$RELEASE_TYPE
popd
fi
gpg --batch --import "${KEYRING}"
for fpr in $(gpg --list-keys --with-colons | awk -F: '/fpr:/ {print $10}' | sort -u);
do
echo -e "5\ny\n" | gpg --batch --command-fd 0 --expert --edit-key $fpr trust;
done
'''
} // END steps
} // END stage
stage ('Build') {
steps {
xvnc(useXauthority: true) {
withMaven(jdk: 'temurin-jdk17-latest', maven: 'apache-maven-3.9.9', options: [junitPublisher(disabled: true), openTasksPublisher(disabled: true)]) {
dir ('git-repo') {
buildProject("org.eclipse.emf.mwe2.target")
}
}
}
} // END steps
post {
success {
archiveArtifacts artifacts: 'git-repo/**/my-local-snapshots-dir/**, git-repo/**/maven/org.eclipse.emf.mwe2.repository/target/repository/**, git-repo/**/maven/org.eclipse.emf.mwe2.repository/target/emft-mwe-2-lang-Update-*.zip'
}
}
} // END stage
stage ('Build Nightly') {
steps {
xvnc(useXauthority: true) {
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
withMaven(jdk: 'temurin-jdk21-latest', maven: 'apache-maven-3.9.9', options: [junitPublisher(disabled: true), openTasksPublisher(disabled: true)]) {
dir ('git-repo-nightly') {
buildProject("org.eclipse.emf.mwe2.target.nightly", true, "4.0.10")
}
}
}
}
} // END steps
} // END stage
stage ('Publish') {
when {
expression { env.BRANCH_NAME == 'master' || params.RELEASE_TYPE != 'Integration' || params.FORCE_PUBLISH }
}
steps {
sshagent(['projects-storage.eclipse.org-bot-ssh']) {
sh '''
REPO_SOURCE_DIR=build-result/p2.repository
# read properties from promote.properties & publisher.properties
# VERSION=$($SCRIPTS/get_property.sh build-result/publisher.properties version)
# BUILD_ID=$($SCRIPTS/get_property.sh build-result/promote.properties build.id)
# BUILD_TYPE=$($SCRIPTS/get_build_type.sh $BUILD_ID)
DROP_DIR=$DOWNLOAD_AREA/$VERSION/$BUILD_ID
cp git-repo/maven/org.eclipse.emf.mwe2.repository/target/repository/*.properties build-result/
#
# STEP 1: Get property values from publisher.properties/promote.properties
#
# read properties from promote.properties & publisher.properties
VERSION=$($SCRIPTS/get_property.sh build-result/publisher.properties version)
BUILD_ID=$($SCRIPTS/get_property.sh build-result/promote.properties build.id)
BUILD_TYPE=$($SCRIPTS/get_build_type.sh $BUILD_ID)
DROP_DIR=$DOWNLOAD_AREA/$VERSION/$BUILD_ID
#
# STEP 2: move built repository to 'build-result' directory
#
#cp -R git-repo/maven/org.eclipse.emf.mwe2.parent/target/apidocs/* build-result/javadoc
mv git-repo/maven/org.eclipse.emf.mwe2.repository/target/repository build-result/p2.repository
mv git-repo/maven/org.eclipse.emf.mwe2.repository/target/emft-mwe-2-lang-Update-$BUILD_ID.zip build-result/downloads/
case "$BUILD_TYPE" in
N) # Nightly
REPO_TARGET_DIR=$PROJECT_STORAGE_PATH/updates/nightly
;;
S) # Stable
REPO_TARGET_DIR=$PROJECT_STORAGE_PATH/updates/milestones/$BUILD_ID
;;
R) # Release
REPO_TARGET_DIR=$PROJECT_STORAGE_PATH/updates/releases/$VERSION
# rename release version: BUILD_ID => VERSION
mv build-result/downloads/emft-mwe-2-lang-Update-$BUILD_ID.zip build-result/downloads/emft-mwe-2-lang-Update-$VERSION.zip
;;
esac
#
# STEP 3: make sure p2 repository exists, cleanup and copy repo to there
#
ssh -x [email protected] mkdir -p $REPO_TARGET_DIR
ssh -x [email protected] rm -rf $REPO_TARGET_DIR/*
scp -r $REPO_SOURCE_DIR/* [email protected]:$REPO_TARGET_DIR
#
# STEP 4: make sure that drop directory exists, cleanup and copy zipped repo to there
#
ssh -x [email protected] mkdir -p $DROP_DIR
ssh -x [email protected] rm -rf $DROP_DIR/*
scp build-result/downloads/emft-mwe-*.zip [email protected]:$DROP_DIR/
#
# STEP 5: Recreate compositeArtifacts.xml & compositeContent.xml
#
case "$RELEASE_TYPE" in
Integration) ;;
GA) # Release
ssh [email protected] 'cat | /bin/bash /dev/stdin' "releases" < $SCRIPTS/create_composite_update_site.sh
# clean up milestone, delete all except for the last 3
# find directories in the milestone update location, only in one level
# remove all except for the last 3 ones
ssh [email protected] 'find $PROJECT_STORAGE_PATH/updates/milestones/ -maxdepth 1 -mindepth 1 -type d |sort|head -n -3 | xargs rm -rf'
# recreate the milestones composite repository
ssh [email protected] 'cat | /bin/bash /dev/stdin' "milestones" < $SCRIPTS/create_composite_update_site.sh;;
*) # Stable
ssh [email protected] 'cat | /bin/bash /dev/stdin' "milestones" < $SCRIPTS/create_composite_update_site.sh;;
esac
ssh [email protected] /bin/bash <<-EOF
# Clean up all nightly drop directories except for the last 5
for f in \\$(find $DOWNLOAD_AREA -type d -name N* -exec basename {} \\; |sort|head -n -5)
do
find $DOWNLOAD_AREA -type d -name \\$f -exec rm -rf {} \\;
done
echo "Kept the following nightly drops:"
find $DOWNLOAD_AREA/ -type d -name N* | sort
# Clean up all milestone drop directories except for the last 5
for f in \\$(find $DOWNLOAD_AREA -type d -name S* -exec basename {} \\; |sort|head -n -5)
do
find $DOWNLOAD_AREA -type d -name \\$f -exec rm -rf {} \\;
done
echo "Kept the following milestone drops:"
find $DOWNLOAD_AREA/ -type d -name S* | sort
# it is important that the end statement in the next line is at the beginning of the line
EOF
'''
} // END sshagent
} // END steps
post {
success {
archiveArtifacts artifacts: 'build-result/**'
}
}
} // END stage
}
post {
always {
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
archiveArtifacts artifacts: '**/target/work/data/.metadata/.log, **/target/work/data/.metadata/bak*.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: '!umPMJdXBGeZgeGiPCM: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>"
}
}
}
}
}
def buildProject(targetPlatform, forceLocalDeployment = false, tychoVersion = "4.0.10") {
withEnv(["TARGET_PLATFORM=$targetPlatform", "FORCE_LOCAL_DEPLOYMENT=$forceLocalDeployment", "TYCHO_VERSION=$tychoVersion"]) {
sh '''
GOALS='clean deploy'
if [ "${FORCE_LOCAL_DEPLOYMENT}" == "true" ] || [ "${BRANCH_NAME}" != "master" ] && [ "${RELEASE_TYPE}" == "Integration" ] && [ "${FORCE_PUBLISH}" != "true" ]; then
GOALS="${GOALS} -DaltDeploymentRepository=snapshot-repo::default::file:./my-local-snapshots-dir"
fi
case "$RELEASE_TYPE" in
Integration) BUILD_TYPE='N' ;;
GA) BUILD_TYPE='R' ;;
*) BUILD_TYPE='S' ;;
esac
mvn \
-e -f maven/org.eclipse.emf.mwe2.parent/pom.xml \
-Dtycho-version=${TYCHO_VERSION} \
-Dsign.skip=false \
-DtestFailureIgnore=true \
-Dmaven.javadoc.failOnError=false \
-Dtycho.localArtifacts=ignore \
-Dtarget-platform=${TARGET_PLATFORM} \
-DBUILD_TYPE=$BUILD_TYPE \
$GOALS
ls -la
find . -name "*my-local-snapshots-dir*"
'''
}
}