forked from verrazzano/verrazzano-monitoring-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
254 lines (229 loc) · 8.67 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
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
// Copyright (c) 2020, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
def DOCKER_IMAGE_TAG
pipeline {
options {
skipDefaultCheckout true
disableConcurrentBuilds()
}
agent {
docker {
image "${RUNNER_DOCKER_IMAGE}"
args "${RUNNER_DOCKER_ARGS}"
registryUrl "${RUNNER_DOCKER_REGISTRY_URL}"
registryCredentialsId 'ocir-pull-and-push-account'
}
}
environment {
DOCKER_CI_IMAGE_NAME_OPERATOR = 'verrazzano-monitoring-operator-jenkins'
DOCKER_PUBLISH_IMAGE_NAME_OPERATOR = 'verrazzano-monitoring-operator'
DOCKER_IMAGE_NAME_OPERATOR = "${env.BRANCH_NAME == 'master' ? env.DOCKER_PUBLISH_IMAGE_NAME_OPERATOR : env.DOCKER_CI_IMAGE_NAME_OPERATOR}"
DOCKER_CI_IMAGE_NAME_ESWAIT = 'verrazzano-monitoring-instance-eswait-jenkins'
DOCKER_PUBLISH_IMAGE_NAME_ESWAIT = 'verrazzano-monitoring-instance-eswait'
DOCKER_IMAGE_NAME_ESWAIT = "${env.BRANCH_NAME == 'master' ? env.DOCKER_PUBLISH_IMAGE_NAME_ESWAIT : env.DOCKER_CI_IMAGE_NAME_ESWAIT}"
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_REPO = 'ghcr.io'
DOCKER_NAMESPACE = 'verrazzano'
HELM_CHART_NAME = 'verrazzano-monitoring-operator'
VMI_NAMESAPCE_PREFIX = 'vmi'
ELASTICSEARCH_VERSION = '7.2.0'
INGRESS_NODE_PORT = sh(script: "shuf -i 30000-32767 -n 1" , returnStdout: true)
KUBECONFIG = '~/.kube/config'
NETRC_FILE = credentials('netrc')
}
stages {
stage('Clean workspace and checkout') {
steps {
checkout scm
sh """
cp -f "${NETRC_FILE}" $HOME/.netrc
chmod 600 $HOME/.netrc
"""
sh """
echo "${DOCKER_CREDS_PSW}" | docker login ${env.DOCKER_REPO} -u ${DOCKER_CREDS_USR} --password-stdin
rm -rf ${GO_REPO_PATH}/verrazzano-monitoring-operator
mkdir -p ${GO_REPO_PATH}/verrazzano-monitoring-operator
tar cf - . | (cd ${GO_REPO_PATH}/verrazzano-monitoring-operator/ ; 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 HEAD").trim()
DOCKER_IMAGE_TAG = "${VERRAZZANO_DEV_VERSION}-${TIMESTAMP}-${SHORT_COMMIT_HASH}"
}
}
}
stage('Build') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-monitoring-operator
make push DOCKER_IMAGE_NAME_OPERATOR=${DOCKER_IMAGE_NAME_OPERATOR} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} K8S_NAMESPACE=${VMI_NAMESAPCE_PREFIX}-${env.BUILD_NUMBER} CREATE_LATEST_TAG=${CREATE_LATEST_TAG}
"""
}
}
stage('gofmt Check') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-monitoring-operator
make go-fmt
"""
}
}
stage('go vet Check') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-monitoring-operator
make go-vet
"""
}
}
stage('golint Check') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-monitoring-operator
make go-lint
"""
}
}
stage('ineffassign Check') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-monitoring-operator
make go-ineffassign
"""
}
}
stage('Third Party License Check') {
when { not { buildingTag() } }
steps {
thirdpartyCheck()
}
}
stage('Copyright Compliance Check') {
when { not { buildingTag() } }
steps {
copyrightScan "${WORKSPACE}"
}
}
stage('Unit Tests') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-monitoring-operator
make unit-test
make -B coverage
cp coverage.html ${WORKSPACE}
build/scripts/copy-junit-output.sh ${WORKSPACE}
"""
}
post {
always {
archiveArtifacts artifacts: '**/coverage.html', allowEmptyArchive: true
junit testResults: '**/*test-result.xml', allowEmptyResults: true
}
}
}
stage('Integration Tests') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-monitoring-operator
echo "To do.."
"""
}
}
stage('basic1 integ tests oke') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-monitoring-operator
echo "To do.."
"""
}
}
stage('basic2 integ tests oke') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-monitoring-operator
echo "To do.."
"""
}
}
stage('basic3 integ tests oke') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-monitoring-operator
echo "To do.."
"""
}
}
stage('basic4 integ tests oke') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-monitoring-operator
echo "To do.."
"""
}
}
stage('Scan Image') {
when { not { buildingTag() } }
steps {
script {
clairScanTemp "${env.DOCKER_REPO}/${env.DOCKER_NAMESPACE}/${DOCKER_IMAGE_NAME_OPERATOR}:${DOCKER_IMAGE_TAG}"
}
sh "mv scanning-report.json verrazzano-monitoring-operator.scanning-report.json"
}
post {
always {
archiveArtifacts artifacts: '**/*scanning-report.json', allowEmptyArchive: true
}
}
}
stage('Build ESWait Image') {
when {
not { buildingTag() }
}
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-monitoring-operator
make push-eswait DOCKER_IMAGE_NAME_ESWAIT=${DOCKER_IMAGE_NAME_ESWAIT} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} CREATE_LATEST_TAG=${CREATE_LATEST_TAG}
"""
}
}
stage('Scan ESWait Image') {
when {
not { buildingTag() }
}
steps {
script {
clairScanTemp "${env.DOCKER_REPO}/${env.DOCKER_NAMESPACE}/${DOCKER_IMAGE_NAME_ESWAIT}:${DOCKER_IMAGE_TAG}"
}
sh "mv scanning-report.json verrazzano-monitoring-instance-eswait.scanning-report.json"
}
post {
always {
archiveArtifacts artifacts: '**/*scanning-report.json', allowEmptyArchive: true
}
}
}
}
post {
failure {
mail to: "${env.BUILD_NOTIFICATION_TO_EMAIL}", from: "${env.BUILD_NOTIFICATION_FROM_EMAIL}",
subject: "Verrazzano: ${env.JOB_NAME} - Failed",
body: "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}"
}
}
}