forked from acidonper/maistra-test-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
189 lines (178 loc) · 7.48 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
@Library('jenkins-common-library')
//Instanciate Objects from Libs
def util = new libs.utils.Util()
// initialize variables in case the token is used
def String OCP_CRED_PSW = ''
def String OCP_CRED_USR = ''
// Parameters to be used on job
properties([
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '20')),
parameters([
string(
name: 'OCP_API_URL',
defaultValue: '',
description: 'OCP Server URL'
),
string(
name: 'OCP_CRED_ID',
defaultValue: 'jenkins-ocp-auto',
description: 'Jenkins credentials ID for OCP cluster. When set this, it takes precedence over OCP_TOKEN.'
),
string(
name: 'OCP_TOKEN',
defaultValue: '',
description: 'OCP token. When OCP_CRED_ID parameter is not empty, OCP_TOKEN will be ignored.'
),
choice(
name: 'OCP_SAMPLE_ARCH',
choices: ['x86','p', 'z', 'arm'],
description: 'This is a switch for bookinfo images on different platforms'
),
string(
name: 'TEST_CASE',
defaultValue: '',
description: 'test case name, e.g. T1, T2. See tests/test_cases.go, default empty value will run all test cases.'
),
choice(
name: 'ROSA',
choices: ['false', 'true'],
description: 'Testing on ROSA'
),
string(
name: 'NIGHTLY',
defaultValue: 'false',
description: 'Install nightly operators from quay.io/maistra'
)
])
])
if (OCP_API_URL == "") {
// Define the build name and informations about it
currentBuild.displayName = "Not Applicable"
currentBuild.description = "Need more info"
echo "Need to inform obrigatory fields!"
} else {
node('jaeger'){
// Define the build name and informations about it
currentBuild.description = util.htmlDescription(util.whoBuild(util.getWhoBuild()))
try {
// Workspace cleanup and git checkout
gitSteps()
stage("Login in Openshift"){
if (OCP_CRED_ID != ""){
echo "Using ${OCP_CRED_ID} credentials ID instead of token parameter."
withCredentials([usernamePassword(credentialsId: OCP_CRED_ID, passwordVariable: 'Password', usernameVariable: 'Username')]) {
OCP_CRED_PSW = Password
OCP_CRED_USR = Username
sh "oc login ${params.OCP_API_URL} -u=${OCP_CRED_USR} -p=${OCP_CRED_PSW} --insecure-skip-tls-verify"
}
} else {
sh "oc login ${params.OCP_API_URL} --token=${params.OCP_TOKEN} --insecure-skip-tls-verify"
}
}
stage("Start running all tests"){
dir('tests') {
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'OCP_CRED_PSW', password: OCP_CRED_PSW]], varMaskRegexes: []]) {
def OUT = sh (
script: """
if [ -z "${params.TEST_CASE}" ];
then docker run \
--name maistra-test-tool-${env.BUILD_NUMBER} \
-d \
--rm \
--pull always \
-e SAMPLEARCH='${params.OCP_SAMPLE_ARCH}' \
-e OCP_CRED_USR='${OCP_CRED_USR}' \
-e OCP_CRED_PSW='${OCP_CRED_PSW}' \
-e OCP_TOKEN='${params.OCP_TOKEN}' \
-e OCP_API_URL='${params.OCP_API_URL}' \
-e NIGHTLY='${params.NIGHTLY}' \
-e ROSA='${params.ROSA}' \
-e GODEBUG=x509ignoreCN=0 \
quay.io/maistra/maistra-test-tool:2.2;
else echo 'Skip';
fi
""",
returnStdout: true
).trim()
println OUT
}
}
}
stage("Start running a single test case"){
dir('tests') {
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[var: 'OCP_CRED_PSW', password: OCP_CRED_PSW]], varMaskRegexes: []]) {
def OUT = sh (
script: """
if [ -z "${params.TEST_CASE}" ];
then echo 'Skip';
else docker run \
--name maistra-test-tool-${env.BUILD_NUMBER} \
-d \
--rm \
--pull always \
-e SAMPLEARCH='${params.OCP_SAMPLE_ARCH}' \
-e OCP_CRED_USR='${OCP_CRED_USR}' \
-e OCP_CRED_PSW='${OCP_CRED_PSW}' \
-e OCP_TOKEN='${params.OCP_TOKEN}' \
-e OCP_API_URL='${params.OCP_API_URL}' \
-e TEST_CASE='${params.TEST_CASE}' \
-e NIGHTLY='${params.NIGHTLY}' \
-e ROSA='${params.ROSA}' \
-e GODEBUG=x509ignoreCN=0 \
--entrypoint "../scripts/pipeline/run_one_test.sh" \
quay.io/maistra/maistra-test-tool:2.2;
fi
""",
returnStdout: true
).trim()
println OUT
}
}
}
stage ("Check Testing Completed") {
def OUT = sh (
script: """
set +ex
docker logs maistra-test-tool-${env.BUILD_NUMBER} | grep "#Testing Completed#"
while [ \$? -ne 0 ]; do sleep 60; docker logs maistra-test-tool-${env.BUILD_NUMBER} | grep "#Testing Completed#"
done
set -ex
""",
returnStdout: true
).trim()
println OUT
}
stage ("Collect logs") {
def OUT = sh (
script: """
docker cp maistra-test-tool-${env.BUILD_NUMBER}:/opt/maistra-test-tool/tests/test.log .
docker cp maistra-test-tool-${env.BUILD_NUMBER}:/opt/maistra-test-tool/tests/results.xml .
""",
returnStdout: true
).trim()
println OUT
}
stage ("Validate Results") {
junit "results.xml"
}
} catch(e) {
currentBuild.result = "FAILED"
throw e
} finally {
archiveArtifacts artifacts: 'test.log,results.xml'
stage("Notify Results"){
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
// Additional information about the build
if (util.getWhoBuild() == "[]") {
executedBy = "Jenkins Trigger"
} else {
executedBy = util.whoBuild(util.getWhoBuild())
}
def moreInfo = "- Executed by: *${executedBy}*"
// Slack message to who ran the job
slackMessage(currentBuild.result,moreInfo,currentBuild.displayName)
}
}
}
}
}