This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
255 lines (236 loc) · 9.56 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
255
// Copyright (c) 2020, 2022, 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
def skipBuild = false
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'
}
}
parameters {
string (name: 'RELEASE_VERSION',
defaultValue: '',
description: 'Release version used for the version of helm chart and tag for the image:\n'+
'When RELEASE_VERSION is not defined, version will be determined by incrementing last minor release version by 1, for example:\n'+
'When RELEASE_VERSION is v0.1.0, image tag will be v0.1.0 and helm chart version is also v0.1.0.\n'+
'When RELEASE_VERSION is not specified and last release version is v0.1.0, image tag will be v0.1.1 and helm chart version is also v0.1.1.',
trim: true)
string (name: 'RELEASE_DESCRIPTION',
defaultValue: '',
description: 'Brief description for the release.',
trim: true)
string (name: 'RELEASE_BRANCH',
defaultValue: 'master',
description: 'Branch to create release from, change this to enable release from a non master branch, e.g.\n'+
'When the branch being built is master then release will always be created when RELEASE_BRANCH has the default value - master.\n'+
'When the branch being built is any non-master branch - release can be created by setting RELEASE_BRANCH to same value as non-master branch, else it is skipped.\n',
trim: true)
}
environment {
DOCKER_CI_IMAGE_NAME = 'verrazzano-operator-jenkins'
DOCKER_PUBLISH_IMAGE_NAME = 'verrazzano-operator'
DOCKER_IMAGE_NAME = "${env.BRANCH_NAME == 'master' ? env.DOCKER_PUBLISH_IMAGE_NAME : env.DOCKER_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_REPO = 'ghcr.io'
DOCKER_NAMESPACE = 'verrazzano'
NETRC_FILE = credentials('netrc')
}
stages {
stage('Clean workspace and checkout') {
steps {
sh "rm -rf github.com/verrazzano/verrazzano-coh-cluster-operator"
sh "rm -rf $GOPATH/pkg/mod/github.com/verrazzano/verrazzano-coh-cluster-operator"
script {
checkout scm
result = sh (script: "git log -1 | grep '.*\\[automatic helm release\\].*'", returnStatus: true)
if (result == 0) {
echo ("'automatic helm release' spotted in git commit. No further stages will be executed.")
skipBuild = true
currentBuild.description = "[automatic helm release] Build Skipped."
sh "exit 0"
}
}
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-operator
mkdir -p ${GO_REPO_PATH}/verrazzano-operator
tar cf - . | (cd ${GO_REPO_PATH}/verrazzano-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 {
allOf {
not { buildingTag() }
equals expected: false, actual: skipBuild
}
}
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-operator
make push DOCKER_REPO=${env.DOCKER_REPO} DOCKER_NAMESPACE=${env.DOCKER_NAMESPACE} DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} CREATE_LATEST_TAG=${CREATE_LATEST_TAG}
"""
}
}
stage('gofmt Check') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-operator
make go-fmt
"""
}
}
stage('go vet Check') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-operator
make go-vet
"""
}
}
stage('golint Check') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-operator
make go-lint
"""
}
}
stage('ineffassign Check') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-operator
make go-ineffassign
"""
}
}
stage('Third Party License Check') {
when {
allOf {
not { buildingTag() }
equals expected: false, actual: skipBuild
}
}
steps {
thirdpartyCheck()
}
}
stage('Copyright Compliance Check') {
when {
allOf {
not { buildingTag() }
equals expected: false, actual: skipBuild
}
}
steps {
copyrightScan "${WORKSPACE}"
}
}
stage('Unit Tests') {
when {
allOf {
not { buildingTag() }
equals expected: false, actual: skipBuild
}
}
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-operator
make unit-test
make -B coverage
cp coverage.html ${WORKSPACE}
cp coverage.xml ${WORKSPACE}
build/scripts/copy-junit-output.sh ${WORKSPACE}
"""
}
post {
always {
archiveArtifacts artifacts: '**/coverage.html', allowEmptyArchive: true
cobertura(coberturaReportFile: 'coverage.xml',
enableNewApi: true,
autoUpdateHealth: false,
autoUpdateStability: false,
failUnstable: true,
failUnhealthy: true,
failNoReports: true,
onlyStable: false,
conditionalCoverageTargets: '50, 0, 0',
fileCoverageTargets: '50, 0, 0',
lineCoverageTargets: '50, 0, 0',
packageCoverageTargets: '80, 0, 0',
)
junit testResults: '**/*test-result.xml', allowEmptyResults: true
}
}
}
stage('Scan Image') {
when {
allOf {
not { buildingTag() }
equals expected: false, actual: skipBuild
}
}
steps {
script {
scanContainerImage "${env.DOCKER_REPO}/${env.DOCKER_NAMESPACE}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}"
}
}
post {
always {
archiveArtifacts artifacts: '**/scanning-report.json', allowEmptyArchive: true
}
}
}
stage('Integration Tests') {
when { not { buildingTag() } }
steps {
sh """
cd ${GO_REPO_PATH}/verrazzano-operator
make integ-test DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG}
build/scripts/copy-junit-output.sh ${WORKSPACE}
"""
}
post {
always {
archiveArtifacts artifacts: '**/coverage.html', allowEmptyArchive: true
junit testResults: '**/*test-result.xml', allowEmptyResults: true
}
}
}
}
post {
failure {
script {
if (env.BRANCH_NAME == "master" || env.BRANCH_NAME ==~ "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}" )
}
}
}
}
}