Skip to content

Commit cb05196

Browse files
committed
Release verification pipeline for Java
1 parent 187a659 commit cb05196

File tree

1 file changed

+313
-0
lines changed

1 file changed

+313
-0
lines changed

jenkins/test_java_release.gy

Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
//
2+
// Pipeline build for Java product
3+
//
4+
// This build, couchbase-lite-java-linux-build-pipeline, is called from
5+
// job couchbase-lite-java only for builds with versions 3.1.x or greater
6+
7+
// Root of the cbdep URL
8+
def CBDEP_ROOT = "https://packages.couchbase.com/cbdep/cbdep"
9+
10+
// These three methods set the tags that determine which agent will run a stage
11+
def static osxNode(version) { return "cbl-java&&macosx_x86_64" }
12+
13+
// Builds 3.1.x or greater use windows 2016
14+
def static windowsNode(version) { return "cbl-java&&windows2016" }
15+
16+
// For now, all builds use CentOS7.
17+
def static linuxNode(version) { return "cbl-java&&centos73" }
18+
19+
static String getRootDir(ws, version) { return "${ws}/cbl-java" }
20+
21+
static String getBuildDir(rootDir, version, edition) {
22+
switch (edition) {
23+
case 'enterprise':
24+
return "${rootDir}/ee/java"
25+
case 'community':
26+
return "${rootDir}/ce/java"
27+
default:
28+
throw new IllegalArgumentException("Bad edition: ${edition}")
29+
}
30+
}
31+
32+
static String uName(credentials) { return credentials.split(":")[0] }
33+
static String pwd(credentials) { return credentials.split(":")[1] }
34+
35+
36+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
37+
////////////////////////////////////////////////// BUILD PIPELINE /////////////////////////////////////////////
38+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
39+
40+
pipeline {
41+
agent { label linuxNode("${VERSION}") }
42+
environment {
43+
LATESTBUILDS = "http://latestbuilds.service.couchbase.com/builds/latestbuilds"
44+
SOURCE = "couchbase-lite-java-${VERSION}-${TEST_SOURCE_BUILD}-source.tar.gz"
45+
CBL_ROOT = getRootDir("${WORKSPACE}", "${VERSION}")
46+
BUILD_DIR = getBuildDir("${CBL_ROOT}", "${VERSION}", "${EDITION}")
47+
CBDEP_URL="${CBDEP_ROOT}-linux-x86_64"
48+
}
49+
options {
50+
skipDefaultCheckout(true)
51+
timeout(time: 2, unit: 'HOURS')
52+
}
53+
stages {
54+
stage('Set build name') {
55+
steps {
56+
script { currentBuild.displayName = "verify-release-${VERSION}-${EDITION}-${BUILD_NUMBER}" }
57+
}
58+
}
59+
60+
stage('Platform Tests') {
61+
parallel {
62+
63+
64+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65+
//////////////////////////////////////////////// O S X T E S T //////////////////////////////////////////////
66+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67+
68+
stage('Test OSX') {
69+
agent { label osxNode("${VERSION}") }
70+
environment {
71+
CBL_ROOT = getRootDir("${WORKSPACE}", "${VERSION}")
72+
BUILD_DIR = getBuildDir("${CBL_ROOT}", "${VERSION}", "${EDITION}")
73+
CBDEP_URL="${CBDEP_ROOT}-darwin"
74+
}
75+
stages {
76+
stage('OSX: Test') {
77+
steps {
78+
// Clean the workspace
79+
cleanWs(deleteDirs: true, disableDeferredWipeout: true)
80+
81+
// Install Java 17 on OSX Test Agent
82+
sh '''#!/bin/bash
83+
export BIN_DIR="${WORKSPACE}/bin"
84+
rm -rf "${BIN_DIR}"
85+
mkdir -p "${BIN_DIR}"
86+
87+
# install cbdeps and put it on the PATH
88+
curl "${CBDEP_URL}" -o "${BIN_DIR}/cbdep"
89+
chmod a+x "${BIN_DIR}/cbdep"
90+
PATH="${BIN_DIR}:${PATH}"
91+
92+
# install openjdk 17
93+
cbdep install -d "${BIN_DIR}" openjdk 17.0.7+7
94+
'''
95+
96+
// Download the source
97+
sh '''#!/bin/bash
98+
echo "======== OSX: Download source: ${SOURCE}"
99+
curl -LO "${LATESTBUILDS}/couchbase-lite-java/${VERSION}/${TEST_SOURCE_BUILD}/${SOURCE}"
100+
101+
echo "======== OSX: Extract source"
102+
tar xzf ${SOURCE}
103+
rm *-source.tar.gz
104+
105+
echo "======== OSX: Force version ${VERSION}"
106+
echo "${VERSION}" > "${CBL_ROOT}/version.txt"
107+
'''
108+
109+
// Run the tests
110+
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
111+
sh '''#!/bin/bash
112+
export JAVA_HOME="${WORKSPACE}/bin/openjdk-17.0.7+7"
113+
export PATH="${JAVA_HOME}/bin:$PATH"
114+
115+
cd "${BUILD_DIR}"
116+
117+
touch "local.properties"
118+
119+
echo "======== OSX: Test in `pwd`"
120+
REPORTS_DIR="$WORKSPACE/reports"
121+
rm -rf "${REPORTS_DIR}"
122+
mkdir -p "${REPORTS_DIR}"
123+
124+
./etc/jenkins/test_macos.sh "RELEASE" "${REPORTS_DIR}" || exit $?
125+
'''
126+
}
127+
128+
// Upload test logs
129+
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
130+
sshPublisher(
131+
continueOnError: true,
132+
failOnError: false,
133+
publishers: [
134+
sshPublisherDesc(
135+
configName: "latestbuilds",
136+
verbose: true,
137+
transfers: [
138+
sshTransfer(
139+
sourceFiles: "reports/*.zip",
140+
removePrefix: "reports",
141+
remoteDirectory: "couchbase-lite-java/${VERSION}/release/${BUILD_NUMBER}",
142+
execCommand: ""
143+
)
144+
])
145+
]
146+
)
147+
}
148+
}
149+
}
150+
}
151+
}
152+
153+
154+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
155+
//////////////////////////////////////////// W I N D O W S T E S T //////////////////////////////////////////
156+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
157+
158+
stage('Test Windows') {
159+
agent { label windowsNode("${VERSION}") }
160+
environment {
161+
CBL_ROOT = getRootDir("${WORKSPACE}", "${VERSION}")
162+
BUILD_DIR = getBuildDir("${CBL_ROOT}", "${VERSION}", "${EDITION}")
163+
CBDEP_URL="${CBDEP_ROOT}-windows.exe"
164+
}
165+
stages {
166+
stage('Win: Test') {
167+
steps {
168+
// Clean the workspace
169+
cleanWs(deleteDirs: true, disableDeferredWipeout: true)
170+
171+
// Install Java 17 on Windows Test Agent
172+
powershell '''
173+
Write-Host "======== Windows: Install Java 17"
174+
[Net.ServicePointManager]::SecurityProtocol = "Tls12, Ssl3"
175+
Invoke-Webrequest -Uri "$env:CBDEP_URL" -Outfile "cbdep.exe"
176+
.\\cbdep.exe install -d $env:WORKSPACE openjdk 17.0.7+7
177+
'''
178+
// Download the source
179+
powershell '''
180+
Write-Host "======== Windows: Download source"
181+
try { (New-Object Net.WebClient).DownloadFile("$env:LATESTBUILDS/couchbase-lite-java/$env:VERSION/$env:TEST_SOURCE_BUILD/$env:SOURCE", "source.tar.gz") }
182+
catch {
183+
Write-Host "Failed with error" $_.Exception.toString()
184+
Exit 5
185+
}
186+
187+
Write-Host "======== Windows: Extract source"
188+
7z x source.tar.gz
189+
Remove-Item $env:SOURCE -Force -ErrorAction SilentlyContinue
190+
7z x -y source.tar
191+
Remove-Item source.tar -Force -ErrorAction SilentlyContinue
192+
193+
Write-Host "======== Windows: Force version" $env:VERSION
194+
Set-Content "$env:CBL_ROOT\\version.txt" -Value "$env:VERSION"
195+
'''
196+
197+
// Run the tests
198+
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
199+
powershell '''
200+
$env:JAVA_HOME = "$env:WORKSPACE\\openjdk-17.0.7+7"
201+
$env:PATH = "$env:JAVA_HOME\\bin;$env:PATH"
202+
203+
try { Set-Location $env:BUILD_DIR }
204+
catch {
205+
Write-Host "Failed with error" $_.Exception.toString()
206+
Exit 5
207+
}
208+
209+
New-Item ".\\local.properties"
210+
211+
Write-Host "======== Windows: Test"
212+
New-Item -ItemType "directory" -Path "$env:WORKSPACE\\reports"
213+
214+
& $env:BUILD_DIR\\etc\\jenkins\\test_windows.ps1 -buildNumber "RELEASE"-reportsDir "$env:WORKSPACE\\reports"
215+
if ($LASTEXITCODE -ne 0) {
216+
Write-Host "Failed with error" $LASTEXITCODE
217+
Exit 5
218+
}
219+
'''
220+
}
221+
222+
// Upload test logs
223+
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
224+
sshPublisher(
225+
continueOnError: true,
226+
failOnError: false,
227+
publishers: [
228+
sshPublisherDesc(
229+
configName: "latestbuilds",
230+
verbose: true,
231+
transfers: [
232+
sshTransfer(
233+
sourceFiles: "reports/*.zip",
234+
removePrefix: "reports",
235+
remoteDirectory: "couchbase-lite-java/${VERSION}/release/${BUILD_NUMBER}",
236+
execCommand: ""
237+
)
238+
])
239+
]
240+
)
241+
}
242+
}
243+
}
244+
}
245+
}
246+
}
247+
}
248+
249+
250+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
251+
//////////////////////////////////////////// L I N U X T E S T //////////////////////////////////////////////
252+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
253+
254+
// It would be great if we could run this stage in parallel.
255+
// If it explicitly requests an agent, it deadlocks this job.
256+
// I wonder if it were in the parallel clause, but didn't have
257+
// an agent specifier, it would run on the current agent...
258+
stage('Linux: Test') {
259+
steps {
260+
// Run the tests
261+
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
262+
sh '''#!/bin/bash
263+
export JAVA_HOME="${WORKSPACE}/bin/openjdk-17.0.7+7"
264+
export PATH="${JAVA_HOME}/bin:$PATH"
265+
266+
cd "${BUILD_DIR}"
267+
268+
echo "======== Linux: Test in `pwd`"
269+
REPORTS_DIR="$WORKSPACE/reports"
270+
rm -rf "${REPORTS_DIR}"
271+
mkdir -p "${REPORTS_DIR}"
272+
273+
./etc/jenkins/test_linux.sh "RELEASE" "${REPORTS_DIR}" || exit $?
274+
'''
275+
}
276+
277+
// Upload test logs
278+
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
279+
sshPublisher(
280+
continueOnError: true,
281+
failOnError: false,
282+
publishers: [
283+
sshPublisherDesc(
284+
configName: "latestbuilds",
285+
verbose: true,
286+
transfers: [
287+
sshTransfer(
288+
sourceFiles: "reports/*.zip",
289+
removePrefix: "reports",
290+
remoteDirectory: "couchbase-lite-java/${VERSION}/release/${BUILD_NUMBER}",
291+
execCommand: ""
292+
)
293+
])
294+
]
295+
)
296+
}
297+
}
298+
}
299+
}
300+
301+
post {
302+
unstable {
303+
mail to: '[email protected]',
304+
subject: "Java build is unstable",
305+
body: "JAVA build ${VERSION}-${EDITION}-release is unstable"
306+
}
307+
failure {
308+
mail to: '[email protected]',
309+
subject: "Java build failed",
310+
body: "JAVA build ${VERSION}-${EDITION}-release} failed"
311+
}
312+
}
313+
}

0 commit comments

Comments
 (0)