forked from zowe/data-sets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
executable file
·212 lines (192 loc) · 7.47 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
#!groovy
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBM Corporation 2018, 2019
*/
node('ibm-jenkins-slave-nvm') {
def lib = library("jenkins-library").org.zowe.jenkins_shared_library
def pipeline = lib.pipelines.gradle.GradlePipeline.new(this)
def uniqueBuildId
pipeline.admins.add("jackjia", "jcain", "stevenh")
// we have extra parameters for integration test
pipeline.addBuildParameters(
string(
name: 'INTEGRATION_TEST_ZOSMF_HOST',
description: 'z/OSMF server for integration test',
defaultValue: 'river.zowe.org',
trim: true,
required: true
),
string(
name: 'INTEGRATION_TEST_ZOSMF_PORT',
description: 'z/OSMF port for integration test',
defaultValue: '10443',
trim: true,
required: true
),
credentials(
name: 'INTEGRATION_TEST_ZOSMF_CREDENTIAL',
description: 'z/OSMF credential for integration test',
credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl',
defaultValue: 'ssh-zdt-test-image-guest-fvt',
required: true
),
string(
name: 'INTEGRATION_TEST_SSH_PORT',
description: 'SSH port for integration test server',
defaultValue: '2022',
trim: true,
required: true
),
string(
name: 'INTEGRATION_TEST_DIRECTORY_ROOT',
description: 'Root directory for integration test',
defaultValue: '/zaas1',
trim: true,
required: true
),
credentials(
name: 'INTEGRATION_TEST_DIRECTORY_INIT_USER',
description: 'z/OSMF credential to initialize integration test folders / files',
credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl',
defaultValue: 'ssh-zdt-test-image-guest',
required: true
)
)
pipeline.setup(
github: [
email : lib.Constants.DEFAULT_GITHUB_ROBOT_EMAIL,
usernamePasswordCredential : lib.Constants.DEFAULT_GITHUB_ROBOT_CREDENTIAL,
],
artifactory: [
url : lib.Constants.DEFAULT_ARTIFACTORY_URL,
usernamePasswordCredential : lib.Constants.DEFAULT_ARTIFACTORY_ROBOT_CREDENTIAL,
]
)
// we have a custom build command
pipeline.build()
pipeline.test(
name : 'Unit',
operation : {
sh './gradlew coverage'
},
junit : '**/test-results/test/*.xml',
htmlReports : [
[dir: "build/reports/jacoco/jacocoFullReport/html", files: "index.html", name: "Report: Code Coverage"],
[dir: "data-sets-api-server/build/reports/tests/test", files: "index.html", name: "Report: Unit Test"],
],
)
pipeline.test(
name : 'Integration',
operation : {
echo "Preparing certificates ..."
sh """keytool -genkeypair -keystore localhost.keystore.p12 -storetype PKCS12 \
-storepass password -alias localhost -keyalg RSA -keysize 2048 -validity 99999 \
-dname \"CN=Zowe Data Sets Explorer API Default Certificate, OU=Zowe API Squad, O=Zowe, L=Hursley, ST=Hampshire, C=UK\" \
-ext san=dns:localhost,ip:127.0.0.1"""
def buildIdentifier = lib.Utils.getBuildIdentifier(env)
uniqueBuildId = "datasets-integration-test-${buildIdentifier}"
if (!uniqueBuildId) {
error "Cannot determine unique build ID."
}
echo "Preparing test folder ..."
withCredentials([
usernamePassword(
credentialsId: params.INTEGRATION_TEST_DIRECTORY_INIT_USER,
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD'
)
]) {
// send file to test image host
sh """SSHPASS=${PASSWORD} sshpass -e sftp -o BatchMode=no -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -b - -P ${params.INTEGRATION_TEST_SSH_PORT} ${USERNAME}@${params.INTEGRATION_TEST_ZOSMF_HOST} << EOF
put scripts/prepare-integration-test-folders.sh
EOF"""
// create TEST_DIRECTORY_ROOT/uniqueBuildId
sh """SSHPASS=${PASSWORD} sshpass -e ssh -tt -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -p ${params.INTEGRATION_TEST_SSH_PORT} ${USERNAME}@${params.INTEGRATION_TEST_ZOSMF_HOST} << EOF
cd ~ && \
(iconv -f ISO8859-1 -t IBM-1047 prepare-integration-test-folders.sh > prepare-integration-test-folders.sh.new) && mv prepare-integration-test-folders.sh.new prepare-integration-test-folders.sh && chmod +x prepare-integration-test-folders.sh
./prepare-integration-test-folders.sh ${params.INTEGRATION_TEST_DIRECTORY_ROOT}/${uniqueBuildId} || { echo "[prepare-integration-test-folders] failed"; exit 1; }
echo "[prepare-integration-test-folders] succeeds" && exit 0
EOF"""
}
echo "Starting test server ..."
sh """java -Xms16m -Xmx512m -Dibm.serversocket.recover=true -Dfile.encoding=UTF-8 \
-Djava.io.tmpdir=/tmp \
-Dserver.port=8443 \
-Dserver.ssl.keyAlias=localhost \
-Dserver.ssl.keyStore=localhost.keystore.p12 \
-Dserver.ssl.keyStorePassword=password \
-Dserver.ssl.keyStoreType=PKCS12 \
-Dzosmf.httpsPort=${params.INTEGRATION_TEST_ZOSMF_PORT} \
-Dzosmf.ipAddress=${params.INTEGRATION_TEST_ZOSMF_HOST} \
-jar \$(ls -1 data-sets-api-server/build/libs/data-sets-api-server-*-boot.jar) &"""
// give it a little time to start the server
sleep time: 1, unit: 'MINUTES'
echo "Starting test ..."
withCredentials([
usernamePassword(
credentialsId: params.INTEGRATION_TEST_ZOSMF_CREDENTIAL,
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD'
)
]) {
sh """./gradlew runIntegrationTests \
-Pserver.host=localhost \
-Pserver.port=8443 \
-Pserver.username=${USERNAME} \
-Pserver.password=${PASSWORD} \
-Pserver.test.directory=${params.INTEGRATION_TEST_DIRECTORY_ROOT}/${uniqueBuildId}"""
}
},
junit : '**/test-results/test/*.xml',
htmlReports : [
[dir: "data-sets-tests/build/reports/tests/test", files: "index.html", name: "Report: Integration Test"],
],
)
pipeline.sonarScan(
scannerServer : lib.Constants.DEFAULT_SONARQUBE_SERVER
)
// how we packaging jars/zips
pipeline.packaging(
name: 'explorer-data-sets',
operation: {
sh './gradlew packageDataSetsApiServer'
}
)
// define we need publish stage
pipeline.publish(
// NOTE: task publishArtifacts will publish to lib-release-local because we don't have SNAPSHOT in version
artifacts: [
'data-sets-zowe-server-package/build/distributions/data-sets-server-zowe-package.zip'
]
)
// define we need release stage
pipeline.release()
pipeline.end(
always: {
// clean up integration test folder
if (uniqueBuildId) {
withCredentials([
usernamePassword(
credentialsId: params.INTEGRATION_TEST_DIRECTORY_INIT_USER,
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD'
)
]) {
// delete TEST_DIRECTORY_ROOT/uniqueBuildId
sh """SSHPASS=${PASSWORD} sshpass -e ssh -tt -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -p ${params.INTEGRATION_TEST_SSH_PORT} ${USERNAME}@${params.INTEGRATION_TEST_ZOSMF_HOST} << EOF
cd ~ && \
[ -d "${params.INTEGRATION_TEST_DIRECTORY_ROOT}/${uniqueBuildId}" ] && \
rm -fr "${params.INTEGRATION_TEST_DIRECTORY_ROOT}/${uniqueBuildId}"
echo "[cleanup-integration-test-folders] done" && exit 0
EOF"""
}
}
}
)
}