This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Jenkinsfile
193 lines (161 loc) · 6.19 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
#!groovy
import java.text.SimpleDateFormat;
@NonCPS
def getChangeDetail() {
def changeDetail = ""
def changes = currentBuild.changeSets
for (int i = 0; i < changes.size(); i++) {
def entries = changes[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
Date entry_timestamp = new Date(entry.timestamp)
SimpleDateFormat timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
changeDetail += "${entry.commitId.take(7)} by [${entry.author}] on ${timestamp.format(entry_timestamp)}: ${entry.msg}\n\n"
}
}
if (!changeDetail) {
changeDetail = "No new changes"
}
return changeDetail
}
IS_MASTER_BRANCH = env.BRANCH_NAME == "master"
IS_RELEASE_BRANCH = (env.BRANCH_NAME ==~ /\d+\.\d+\.\d+/)
def sendEmailNotification() {
if (!(IS_MASTER_BRANCH || IS_RELEASE_BRANCH)) {
println "Skipping email step since branch condition was not met"
return
}
final def EXTRECIPIENTS = emailextrecipients([
[$class: 'CulpritsRecipientProvider'],
[$class: 'RequesterRecipientProvider'],
[$class: 'DevelopersRecipientProvider']
])
def RECIPIENTS = EXTRECIPIENTS != null ? EXTRECIPIENTS : env.CHANGE_AUTHOR_EMAIL;
def SUBJECT = "${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${currentBuild.currentResult}!"
def CHANGE = getChangeDetail();
emailext(
to: RECIPIENTS,
subject: "${SUBJECT}",
body: """
<b>Build result:</b>
<br><br>
${currentBuild.currentResult}
<br><br>
<b>Project name - Build number:</b>
<br><br>
${currentBuild.fullProjectName} - Build #${env.BUILD_NUMBER}
<br><br>
<b>Check console output for more detail:</b>
<br><br>
<a href="${currentBuild.absoluteUrl}console">${currentBuild.absoluteUrl}console</a>
<br><br>
<b>Changes:</b>
<br><br>
${CHANGE}
<br><br>
"""
);
}
pipeline {
agent {
kubernetes {
label 'node'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: node
image: node:lts
tty: true
command:
- cat
"""
}
}
options {
timestamps()
skipStagesAfterUnstable()
}
environment {
// https://stackoverflow.com/a/43264045
HOME="."
}
stages {
stage('Build') {
steps {
container("node") {
dir('dev') {
sh '''#!/usr/bin/env bash
# Test compilation to catch any errors
npm run vscode:prepublish
# Package for prod
npm i vsce
npx vsce package
# rename to have datetime for clarity + prevent collisions
export artifact_name=$(basename *.vsix)
mv -v $artifact_name ${artifact_name/.vsix/_$(date +'%F-%H%M').vsix}
'''
// Note there must be exactly one .vsix
stash includes: '*.vsix', name: 'deployables'
}
}
}
}
stage ('Deploy') {
// This when clause disables PR build uploads; you may comment this out if you want your build uploaded.
when {
beforeAgent true
not {
changeRequest()
}
}
options {
skipDefaultCheckout()
}
agent any
steps {
sshagent (['projects-storage.eclipse.org-bot-ssh']) {
unstash 'deployables'
println("Deploying codewind-openapi-vscode to archive area...")
sh '''#!/usr/bin/env bash
export REPO_NAME="codewind-openapi-vscode"
export OUTPUT_NAME="codewind-openapi-tools"
export ARCHIVE_AREA_URL="https://archive.eclipse.org/codewind/$REPO_NAME"
export LATEST_DIR="latest"
export BUILD_INFO="build_info.properties"
export sshHost="[email protected]"
export deployDir="/home/data/httpd/archive.eclipse.org/codewind/$REPO_NAME"
if [ -z $CHANGE_ID ]; then
UPLOAD_DIR="$GIT_BRANCH/$BUILD_ID"
BUILD_URL="$ARCHIVE_AREA_URL/$UPLOAD_DIR"
ssh $sshHost rm -rf $deployDir/$GIT_BRANCH/$LATEST_DIR
ssh $sshHost mkdir -p $deployDir/$GIT_BRANCH/$LATEST_DIR
cp $OUTPUT_NAME-*.vsix $OUTPUT_NAME.vsix
scp $OUTPUT_NAME.vsix $sshHost:$deployDir/$GIT_BRANCH/$LATEST_DIR/$OUTPUT_NAME.vsix
echo "# Build date: $(date +%F-%T)" >> $BUILD_INFO
echo "build_info.url=$BUILD_URL" >> $BUILD_INFO
SHA1=$(sha1sum ${OUTPUT_NAME}.vsix | cut -d ' ' -f 1)
echo "build_info.SHA-1=${SHA1}" >> $BUILD_INFO
scp $BUILD_INFO $sshHost:$deployDir/$GIT_BRANCH/$LATEST_DIR/$BUILD_INFO
rm $BUILD_INFO
rm $OUTPUT_NAME.vsix
else
UPLOAD_DIR="pr/$CHANGE_ID/$BUILD_ID"
fi
ssh $sshHost rm -rf $deployDir/${UPLOAD_DIR}
ssh $sshHost mkdir -p $deployDir/${UPLOAD_DIR}
ls *.vsix
scp -r *.vsix $sshHost:$deployDir/${UPLOAD_DIR}
echo "Uploaded to https://archive.eclipse.org${deployDir##*archive.eclipse.org}"
'''
}
}
}
}
post {
failure {
sendEmailNotification()
}
}
}