forked from verrazzano/verrazzano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JenkinsfileCopyrightTest
282 lines (257 loc) · 13.7 KB
/
JenkinsfileCopyrightTest
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
//
// This is temporary, to experiment with the Git settings in the Jenkins pipelines
def DOCKER_IMAGE_TAG
def SKIP_ACCEPTANCE_TESTS = false
pipeline {
options {
skipDefaultCheckout true
}
agent {
docker {
image "${RUNNER_DOCKER_IMAGE}"
args "${RUNNER_DOCKER_ARGS}"
registryUrl "${RUNNER_DOCKER_REGISTRY_URL}"
registryCredentialsId 'ocir-pull-and-push-account'
label "large"
}
}
parameters {
booleanParam (description: 'Whether to kick off acceptance test run at the end of this build', name: 'RUN_ACCEPTANCE_TESTS', defaultValue: true)
booleanParam (description: 'Whether to run example tests', name: 'RUN_EXAMPLE_TESTS', defaultValue: true)
booleanParam (description: 'Whether to dump k8s cluster on success (off by default can be useful to capture for comparing to failed cluster)', name: 'DUMP_K8S_CLUSTER_ON_SUCCESS', defaultValue: false)
}
environment {
DOCKER_PLATFORM_CI_IMAGE_NAME = 'verrazzano-platform-operator-jenkins'
DOCKER_PLATFORM_PUBLISH_IMAGE_NAME = 'verrazzano-platform-operator'
DOCKER_PLATFORM_IMAGE_NAME = "${env.BRANCH_NAME == 'develop' || env.BRANCH_NAME == 'master' ? env.DOCKER_PLATFORM_PUBLISH_IMAGE_NAME : env.DOCKER_PLATFORM_CI_IMAGE_NAME}"
DOCKER_OAM_CI_IMAGE_NAME = 'verrazzano-application-operator-jenkins'
DOCKER_OAM_PUBLISH_IMAGE_NAME = 'verrazzano-application-operator'
DOCKER_OAM_IMAGE_NAME = "${env.BRANCH_NAME == 'develop' || env.BRANCH_NAME == 'master' ? env.DOCKER_OAM_PUBLISH_IMAGE_NAME : env.DOCKER_OAM_CI_IMAGE_NAME}"
CREATE_LATEST_TAG = "${env.BRANCH_NAME == 'master' ? '1' : '0'}"
GOPATH = '/home/opc/go'
GO_REPO_PATH = "${GOPATH}/src/github.com/verrazzano"
DOCKER_CREDS = credentials('github-packages-credentials-rw')
DOCKER_EMAIL = credentials('github-packages-email')
DOCKER_REPO = 'ghcr.io'
DOCKER_NAMESPACE = 'verrazzano'
NETRC_FILE = credentials('netrc')
SERVICE_KEY = credentials('PAGERDUTY_SERVICE_KEY')
CLUSTER_NAME = 'verrazzano'
POST_DUMP_FAILED_FILE = "${WORKSPACE}/post_dump_failed_file.tmp"
TESTS_EXECUTED_FILE = "${WORKSPACE}/tests_executed_file.tmp"
KUBECONFIG = "${WORKSPACE}/test_kubeconfig"
VERRAZZANO_KUBECONFIG = "${KUBECONFIG}"
OCR_CREDS = credentials('ocr-pull-and-push-account')
OCR_REPO = 'container-registry.oracle.com'
IMAGE_PULL_SECRET = 'verrazzano-container-registry'
INSTALL_CONFIG_FILE_KIND = "./tests/e2e/config/scripts/v1beta1/install-verrazzano-kind.yaml"
INSTALL_PROFILE = "dev"
VZ_ENVIRONMENT_NAME = "default"
WEBLOGIC_PSW = credentials('weblogic-example-domain-password') // Needed by ToDoList example test
DATABASE_PSW = credentials('todo-mysql-password') // Needed by ToDoList example test
}
stages {
stage('Clean workspace and checkout') {
steps {
sh """
echo "${NODE_LABELS}"
"""
script {
checkout scm
}
sh """
cp -f "${NETRC_FILE}" $HOME/.netrc
chmod 600 $HOME/.netrc
"""
script {
try {
sh """
echo "${DOCKER_CREDS_PSW}" | docker login ${env.DOCKER_REPO} -u ${DOCKER_CREDS_USR} --password-stdin
"""
} catch(error) {
echo "docker login failed, retrying after sleep"
retry(4) {
sleep(30)
sh """
echo "${DOCKER_CREDS_PSW}" | docker login ${env.DOCKER_REPO} -u ${DOCKER_CREDS_USR} --password-stdin
"""
}
}
}
script {
try {
sh """
echo "${OCR_CREDS_PSW}" | docker login -u ${OCR_CREDS_USR} ${OCR_REPO} --password-stdin
"""
} catch(error) {
echo "OCR docker login failed, retrying after sleep"
retry(4) {
sleep(30)
sh """
echo "${OCR_CREDS_PSW}" | docker login -u ${OCR_CREDS_USR} ${OCR_REPO} --password-stdin
"""
}
}
}
sh """
rm -rf ${GO_REPO_PATH}/verrazzano
mkdir -p ${GO_REPO_PATH}/verrazzano
tar cf - . | (cd ${GO_REPO_PATH}/verrazzano/ ; tar xf -)
"""
script {
def props = readProperties file: '.verrazzano-development-version'
VERRAZZANO_DEV_VERSION = props['verrazzano-development-version']
TIMESTAMP = sh(returnStdout: true, script: "date +%Y%m%d%H%M%S").trim()
SHORT_COMMIT_HASH = sh(returnStdout: true, script: "git rev-parse --short=8 HEAD").trim()
DOCKER_IMAGE_TAG = "${VERRAZZANO_DEV_VERSION}-${TIMESTAMP}-${SHORT_COMMIT_HASH}"
}
}
}
// cd ${GO_REPO_PATH}/verrazzano
stage('Quality and Compliance Checks') {
when { not { buildingTag() } }
steps {
sh """
echo "copyright scan"
echo "working directory"
pwd
git branch
git diff --name-only "@{2001-01-01}" "@{now}"
git diff origin/master --name-only
git log --since=01-01-2021 --name-only --oneline --pretty="format:" | sort -u
time make copyright-check
./ci/scripts/check_if_clean_after_generate.sh
"""
}
}
}
post {
always {
script {
if ( fileExists(env.TESTS_EXECUTED_FILE) ) {
dumpVerrazzanoSystemPods()
dumpCattleSystemPods()
dumpNginxIngressControllerLogs()
dumpVerrazzanoPlatformOperatorLogs()
dumpVerrazzanoApplicationOperatorLogs()
dumpOamKubernetesRuntimeLogs()
dumpVerrazzanoApiLogs()
}
}
archiveArtifacts artifacts: '**/coverage.html,**/logs/**,**/verrazzano_images.txt,**/*cluster-snapshot*/**', allowEmptyArchive: true
junit testResults: '**/*test-result.xml', allowEmptyResults: true
sh """
cd ${GO_REPO_PATH}/verrazzano/platform-operator
make delete-cluster
if [ -f ${POST_DUMP_FAILED_FILE} ]; then
echo "Failures seen during dumping of artifacts, treat post as failed"
exit 1
fi
"""
deleteDir()
}
failure {
script {
if (env.JOB_NAME == "verrazzano/master" || env.JOB_NAME ==~ "verrazzano/release-*" || env.BRANCH_NAME ==~ "mark/*") {
slackSend ( message: "Job Failed - \"${env.JOB_NAME}\" build: ${env.BUILD_NUMBER}\n\nView the log at:\n ${env.BUILD_URL}\n\nBlue Ocean:\n${env.RUN_DISPLAY_URL}" )
}
}
}
}
}
def runGinkgoRandomize(testSuitePath) {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh """
cd ${GO_REPO_PATH}/verrazzano/tests/e2e
ginkgo -p --randomize-all -v --keep-going --no-color ${testSuitePath}/...
"""
}
}
def runGinkgo(testSuitePath) {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh """
cd ${GO_REPO_PATH}/verrazzano/tests/e2e
ginkgo -v --keep-going --no-color ${testSuitePath}/...
"""
}
}
def dumpK8sCluster(dumpDirectory) {
sh """
mkdir -p ${dumpDirectory}/cluster-snapshot
${GO_REPO_PATH}/verrazzano/tools/scripts/k8s-dump-cluster.sh -d ${dumpDirectory}/cluster-snapshot -r ${dumpDirectory}/cluster-snapshot/analysis.report
${GO_REPO_PATH}/vz bug-report --report-file ${dumpDirectory}/bug-report.tar.gz
mkdir -p ${dumpDirectory}/bug-report
tar -xvf ${dumpDirectory}/bug-report.tar.gz -C ${dumpDirectory}/bug-report
"""
}
def dumpVerrazzanoSystemPods() {
sh """
cd ${GO_REPO_PATH}/verrazzano/platform-operator
export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/verrazzano-system-pods.log"
./scripts/install/k8s-dump-objects.sh -o pods -n verrazzano-system -m "verrazzano system pods" || echo "failed" > ${POST_DUMP_FAILED_FILE}
export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/verrazzano-system-certs.log"
./scripts/install/k8s-dump-objects.sh -o cert -n verrazzano-system -m "verrazzano system certs" || echo "failed" > ${POST_DUMP_FAILED_FILE}
export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/verrazzano-system-osd.log"
./scripts/install/k8s-dump-objects.sh -o pods -n verrazzano-system -r "vmi-system-osd-*" -m "verrazzano system opensearchdashboards log" -l -c osd || echo "failed" > ${POST_DUMP_FAILED_FILE}
export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/verrazzano-system-es-master.log"
./scripts/install/k8s-dump-objects.sh -o pods -n verrazzano-system -r "vmi-system-es-master-*" -m "verrazzano system opensearchdashboards log" -l -c es-master || echo "failed" > ${POST_DUMP_FAILED_FILE}
"""
}
def dumpCattleSystemPods() {
sh """
cd ${GO_REPO_PATH}/verrazzano/platform-operator
export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/cattle-system-pods.log"
./scripts/install/k8s-dump-objects.sh -o pods -n cattle-system -m "cattle system pods" || echo "failed" > ${POST_DUMP_FAILED_FILE}
export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/rancher.log"
./scripts/install/k8s-dump-objects.sh -o pods -n cattle-system -r "rancher-*" -m "Rancher logs" -l || echo "failed" > ${POST_DUMP_FAILED_FILE}
"""
}
def dumpNginxIngressControllerLogs() {
sh """
cd ${GO_REPO_PATH}/verrazzano/platform-operator
export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/nginx-ingress-controller.log"
./scripts/install/k8s-dump-objects.sh -o pods -n ingress-nginx -r "nginx-ingress-controller-*" -m "Nginx Ingress Controller" -l || echo "failed" > ${POST_DUMP_FAILED_FILE}
"""
}
def dumpVerrazzanoPlatformOperatorLogs() {
sh """
## dump out verrazzano-platform-operator logs
mkdir -p ${WORKSPACE}/verrazzano-platform-operator/logs
kubectl -n verrazzano-install logs --selector=app=verrazzano-platform-operator > ${WORKSPACE}/verrazzano-platform-operator/logs/verrazzano-platform-operator-pod.log --tail -1 || echo "failed" > ${POST_DUMP_FAILED_FILE}
kubectl -n verrazzano-install describe pod --selector=app=verrazzano-platform-operator > ${WORKSPACE}/verrazzano-platform-operator/logs/verrazzano-platform-operator-pod.out || echo "failed" > ${POST_DUMP_FAILED_FILE}
echo "verrazzano-platform-operator logs dumped to verrazzano-platform-operator-pod.log"
echo "verrazzano-platform-operator pod description dumped to verrazzano-platform-operator-pod.out"
echo "------------------------------------------"
"""
}
def dumpVerrazzanoApplicationOperatorLogs() {
sh """
## dump out verrazzano-application-operator logs
mkdir -p ${WORKSPACE}/verrazzano-application-operator/logs
kubectl -n verrazzano-system logs --selector=app=verrazzano-application-operator > ${WORKSPACE}/verrazzano-application-operator/logs/verrazzano-application-operator-pod.log --tail -1 || echo "failed" > ${POST_DUMP_FAILED_FILE}
kubectl -n verrazzano-system describe pod --selector=app=verrazzano-application-operator > ${WORKSPACE}/verrazzano-application-operator/logs/verrazzano-application-operator-pod.out || echo "failed" > ${POST_DUMP_FAILED_FILE}
echo "verrazzano-application-operator logs dumped to verrazzano-application-operator-pod.log"
echo "verrazzano-application-operator pod description dumped to verrazzano-application-operator-pod.out"
echo "------------------------------------------"
"""
}
def dumpOamKubernetesRuntimeLogs() {
sh """
## dump out oam-kubernetes-runtime logs
mkdir -p ${WORKSPACE}/oam-kubernetes-runtime/logs
kubectl -n verrazzano-system logs --selector=app.kubernetes.io/instance=oam-kubernetes-runtime > ${WORKSPACE}/oam-kubernetes-runtime/logs/oam-kubernetes-runtime-pod.log --tail -1 || echo "failed" > ${POST_DUMP_FAILED_FILE}
kubectl -n verrazzano-system describe pod --selector=app.kubernetes.io/instance=oam-kubernetes-runtime > ${WORKSPACE}/verrazzano-application-operator/logs/oam-kubernetes-runtime-pod.out || echo "failed" > ${POST_DUMP_FAILED_FILE}
echo "verrazzano-application-operator logs dumped to oam-kubernetes-runtime-pod.log"
echo "verrazzano-application-operator pod description dumped to oam-kubernetes-runtime-pod.out"
echo "------------------------------------------"
"""
}
def dumpVerrazzanoApiLogs() {
sh """
cd ${GO_REPO_PATH}/verrazzano/platform-operator
export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/verrazzano-authproxy.log"
./scripts/install/k8s-dump-objects.sh -o pods -n verrazzano-system -r "verrazzano-authproxy-*" -m "verrazzano api" -l || echo "failed" > ${POST_DUMP_FAILED_FILE}
"""
}