forked from strimzi/strimzi-kafka-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-pr
208 lines (205 loc) · 9.35 KB
/
Jenkinsfile-pr
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
#!/usr/bin/env groovy
def lib
def NODE_LABEL = null
def DEFAULT_EXCLUDED_GROUPS = null
node('master') {
stage('Set agent label') {
echo "Github PR comment: ${env.ghprbCommentBody}"
if (env.ghprbCommentBody.contains('crc') || env.ghprbCommentBody.contains('ocp4')) {
NODE_LABEL = "strimzi-crc"
DEFAULT_EXCLUDED_GROUPS = "loadbalancer"
} else {
NODE_LABEL = 'strimzi-pr'
DEFAULT_EXCLUDED_GROUPS = "networkpolicies"
}
}
}
pipeline {
agent {
node {
label "${NODE_LABEL}"
}
}
parameters {
string(name: 'TEST_CASE', defaultValue: '*ST', description: 'maven parameter for executing specific tests')
string(name: 'TEST_PROFILE', defaultValue: 'acceptance', description: 'maven parameter for executing specific test profile')
string(name: 'EXCLUDE', defaultValue: "${DEFAULT_EXCLUDED_GROUPS}", description: 'maven parameter for exclude specific test tag')
string(name: 'ENV_VARS', defaultValue: "", description: 'maven parameter for setting values of environment variables used in STs')
}
options {
timeout(time: 22, unit: 'HOURS')
ansiColor('xterm')
}
environment {
ARTIFACTS_DIR = 'systemtest/target/logs'
JOB_NAME_SUB = "${String.format("%.15s", JOB_NAME).toLowerCase()}"
ORIGIN_BASE_DIR = "${env.WORKSPACE}/origin/"
KUBE_CONFIG_PATH = "${env.WORKSPACE}/origin/kube-apiserver/admin.kubeconfig"
TEST_CLUSTER_ADMIN = "admin"
OPERATOR_IMAGE_PULL_POLICY = "IfNotPresent"
COMPONENTS_IMAGE_PULL_POLICY = "IfNotPresent"
JAVA_VERSION = "11"
TEST_HELM2_VERSION = "v2.16.3"
TEST_HELM3_VERSION = "v3.2.0"
}
stages {
stage('Clean WS') {
steps {
cleanWs()
}
}
stage('Checkout Strimzi') {
steps {
checkout scm
}
}
stage('Parse parameters from comment') {
steps {
script {
echo "Comment body: ${env.ghprbCommentBody}"
env.TEST_CASE = params.TEST_CASE
env.TEST_PROFILE = params.TEST_PROFILE
env.ENV_VARS = params.ENV_VARS
env.OC_VERSION = NODE_LABEL == 'strimzi-crc' ? "4" : "3"
env.EXCLUDE_GROUPS = DEFAULT_EXCLUDED_GROUPS
if (env.ghprbCommentBody.contains('testcase=')) {
env.TEST_CASE = env.ghprbCommentBody.split('testcase=')[1].split(/\s/)[0]
}
echo "TEST_CASE: ${env.TEST_CASE}"
if (env.ghprbCommentBody.contains('profile=')) {
env.TEST_PROFILE = env.ghprbCommentBody.split('profile=')[1].split(/\s/)[0]
if (env.TEST_PROFILE != "flaky") {
env.EXCLUDE_GROUPS = env.EXCLUDE_GROUPS + ",flaky"
}
}
echo "TEST_PROFILE: ${env.TEST_PROFILE}"
if (env.ghprbCommentBody.contains('exclude=')) {
env.EXCLUDE_GROUPS = env.EXCLUDE_GROUPS + ',' + env.ghprbCommentBody.split('exclude=')[1].split(/\s/)[0]
}
echo "EXCLUDE_GROUPS: ${env.EXCLUDE_GROUPS}"
if (env.ghprbCommentBody.contains('test_only')) {
env.TEST_ONLY = true
env.DOCKER_REGISTRY = "docker.io"
env.DOCKER_ORG="strimzi"
env.DOCKER_TAG = "latest"
} else {
env.TEST_ONLY = false
env.DOCKER_ORG="strimzi"
env.DOCKER_REGISTRY = env.OC_VERSION == "3" ? "172.30.1.1:5000" : "default-route-openshift-image-registry.apps-crc.testing"
env.DOCKER_TAG="pr"
}
if (env.ghprbCommentBody.contains('install_type=')) {
env.CLUSTER_OPERATOR_INSTALL_TYPE = env.ghprbCommentBody.split('install_type=')[1].split(/\s/)[0]
}
if (env.ghprbCommentBody.contains('env=')) {
env.ENV_VARS = env.ghprbCommentBody.split('env=')[1]
for (envVar in "${env.ENV_VARS}".split(",")) {
env.(envVar.split("=")[0]) = envVar.split("=")[1]
println("${env.(envVar.split("=")[0])}")
}
}
echo "ENV_VARS: ${env.ENV_VARS}"
env.BUILD_PROJECT_STATUS = false
env.BUILD_DOCKER_IMAGE_STATUS = false
echo "TEST_ONLY: ${env.TEST_ONLY}"
echo "DOCKER_REGISTRY: ${env.DOCKER_REGISTRY}"
echo "DOCKER_ORG: ${env.DOCKER_ORG}"
echo "DOCKER_TAG: ${env.DOCKER_TAG}"
echo "CLUSTER_OPERATOR_INSTALL_TYPE: ${env.CLUSTER_OPERATOR_INSTALL_TYPE}"
}
}
}
stage('Start Openshift') {
steps {
timeout(time: 50, unit: 'MINUTES') {
script {
lib = evaluate readFile('./jenkins.groovy')
if (env.OC_VERSION == "3") {
lib.startOrigin()
} else {
lib.startCRC()
}
}
}
}
}
stage('Install Helm') {
steps {
timeout(time: 10, unit: 'MINUTES') {
script {
lib.installHelm(env.WORKSPACE)
}
}
}
}
stage('Install yq') {
steps {
timeout(time: 5, unit: 'MINUTES') {
script {
lib.installYq(env.WORKSPACE)
}
}
}
}
stage('Build project') {
steps {
script {
withMaven(mavenOpts: '-Djansi.force=true') {
sh "mvn clean install -DskipTests -Dstyle.color=always --no-transfer-progress"
env.BUILD_PROJECT_STATUS = true
}
}
}
}
stage('Build images') {
when {
environment name: 'TEST_ONLY', value: 'false'
}
steps {
script {
lib.buildStrimziImages()
env.BUILD_DOCKER_IMAGE_STATUS = true
}
}
}
stage('Execute system tests') {
steps {
script {
catchError {
if (env.OC_VERSION == "4" && !env.ghprbCommentBody.contains('test_only')) {
env.DOCKER_REGISTRY = "image-registry.openshift-image-registry.svc:5000"
}
// For upgrade tests running with locally built images we need to change tag in StrimziUpgradeST.json
if ("${env.TEST_PROFILE}".contains("upgrade")) {
println("[INFO] Update files for upgrade procedure")
sh(script: """
sed -i 's#:latest#:${env.DOCKER_TAG}#g' ${env.WORKSPACE}/systemtest/src/main/resources/StrimziUpgradeST.json ${env.WORKSPACE}/install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml
sed -i 's#strimzi/test-client:${env.DOCKER_TAG}#${env.DOCKER_REGISTRY}/strimzi/test-client:${env.DOCKER_TAG}#g' ${env.WORKSPACE}/systemtest/src/main/resources/StrimziUpgradeST.json
sed -i 's#strimzi/#${env.DOCKER_REGISTRY}/strimzi/#g' ${env.WORKSPACE}/install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml
sed -i 's#/opt/${env.DOCKER_REGISTRY}#/opt#g' ${env.WORKSPACE}/install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml
""")
sh(script: "cat ${env.WORKSPACE}/systemtest/src/main/resources/StrimziUpgradeST.json")
sh(script: "cat ${env.WORKSPACE}/install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml")
}
lib.runSystemTests(env.WORKSPACE, env.TEST_CASE, env.TEST_PROFILE, env.EXCLUDE_GROUPS)
}
}
}
}
}
post {
always {
script {
sh "sudo ./systemtest/scripts/results_info.sh ./systemtest/target/failsafe-reports/ ${env.TEST_CASE} ${env.TEST_PROFILE} ${env.BUILD_NUMBER} ${env.OC_VERSION} ${env.TEST_ONLY} ${env.EXCLUDE_GROUPS} ${env.ENV_VARS}"
lib.postGithubPrComment("results.json")
lib.postAction(env.ARTIFACTS_DIR, env.ghprbPullId, env.ghprbActualCommitAuthor, env.ghprbPullTitle, env.ghprbPullLink, env.BUILD_URL, env.WORKSPACE, env.STRIMZI_MAILING_LIST)
}
}
failure {
echo "Build failed"
script {
lib.sendMail(env.STRIMZI_MAILING_LIST, "failed", env.ghprbPullId, env.ghprbActualCommitAuthor, env.ghprbPullTitle, env.ghprbPullLink, env.BUILD_URL)
}
}
}
}