This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathJenkinsfile
197 lines (183 loc) · 6.33 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
pipeline {
agent {
node {
label "psi_rhel7_openshift311"
}
}
libraries {
lib('fh-pipeline-library')
lib('qe-pipeline-library')
}
environment {
GOPATH = "${env.WORKSPACE}/"
PATH = "${env.PATH}:${env.WORKSPACE}/bin:/usr/local/go/bin"
GOOS = "linux"
GOARCH = "amd64"
CGO_ENABLED = 0
OPERATOR_NAME = "unifiedpush-operator"
OPERATOR_CONTAINER_IMAGE_CANDIDATE_NAME = "quay.io/aerogear/${env.OPERATOR_NAME}:candidate-${env.BRANCH_NAME}"
OPERATOR_CONTAINER_IMAGE_NAME = "quay.io/aerogear/${env.OPERATOR_NAME}:${env.BRANCH_NAME}"
OPERATOR_CONTAINER_IMAGE_NAME_LATEST = "quay.io/aerogear/${env.OPERATOR_NAME}:latest"
OPENSHIFT_PROJECT_NAME = "unifiedpush"
CLONED_REPOSITORY_PATH = "src/github.com/aerogear/unifiedpush-operator"
CREDENTIALS_ID = "quay-aerogear-bot"
QUAY_TOKEN_ID = "quay-aerogear-token"
}
options {
checkoutToSubdirectory("src/github.com/aerogear/unifiedpush-operator")
}
stages {
stage("Trust"){
steps{
enforceTrustedApproval('aerogear')
}
post{
failure{
echo "====++++'Trust' execution failed++++===="
echo "You are not authorized to run this job"
}
}
}
stage("Run oc-cluster-up"){
steps{
// qe-pipeline-library step
ocClusterUp()
}
post{
failure{
echo "====++++Run oc-cluster-up execution failed++++===="
echo "Try to rerun the job"
}
}
}
stage("Install Operator SDK") {
steps {
// qe-pipeline-library step
installOperatorSdk version: "v0.10.0"
}
post {
failure {
echo "====++++'Install Operator SDK' execution failed++++===="
echo "Please check if the version of operator-sdk you provided exists"
echo "https://github.com/operator-framework/operator-sdk/releases"
}
}
}
stage("Create an OpenShift project") {
steps {
// qe-pipeline-library step
newOpenshiftProject "${env.OPENSHIFT_PROJECT_NAME}"
}
}
stage("Build code binary"){
steps{
dir("${env.CLONED_REPOSITORY_PATH}") {
sh "make code/compile"
}
}
post{
failure{
echo "====++++'Build code binary' execution failed++++===="
echo "Try to run 'make code/compile' locally and make sure it pass"
}
}
}
stage("Run unit tests"){
steps{
dir("${env.CLONED_REPOSITORY_PATH}") {
sh "make test/unit"
}
}
post{
failure{
echo "====++++'Run unit tests' execution failed++++===="
echo "Try to run 'make test/unit' locally and make sure it passes"
}
}
}
stage("Build & push container image") {
steps{
dir("${env.CLONED_REPOSITORY_PATH}") {
// qe-pipeline-library step
dockerBuildAndPush(
credentialsId: "${env.CREDENTIALS_ID}",
containerRegistryServerName: "quay.io",
containerImageName: "${env.OPERATOR_CONTAINER_IMAGE_CANDIDATE_NAME}",
pathToDockerfile: "build/Dockerfile"
)
}
}
post{
failure{
echo "====++++'Build & push container image' execution failed++++===="
}
}
}
stage("Build test binary"){
steps{
dir("${env.CLONED_REPOSITORY_PATH}") {
script {
sh "make test/compile"
}
}
}
post{
failure{
echo "====++++'Build test binary' execution failed++++===="
echo "Try to run 'make test/compile' locally and make sure it pass"
}
}
}
stage("Test operator") {
steps{
dir("${env.CLONED_REPOSITORY_PATH}") {
// qe-pipeline-library step
runOperatorTestWithImage (
containerImageName: "${env.OPERATOR_CONTAINER_IMAGE_CANDIDATE_NAME}",
namespace: "${env.OPENSHIFT_PROJECT_NAME}"
)
}
}
post{
failure{
echo "====++++Test operator execution failed++++===="
}
}
}
stage("Retag the image if the test passed and delete an old tag") {
steps{
// qe-pipeline-library step
tagRemoteContainerImage(
credentialsId: "${env.CREDENTIALS_ID}",
bearerToken: "${env.QUAY_TOKEN_ID}",
sourceImage: "${env.OPERATOR_CONTAINER_IMAGE_CANDIDATE_NAME}",
targetImage: "${env.OPERATOR_CONTAINER_IMAGE_NAME}",
deleteOriginalImage: true
)
}
}
stage("Create a 'latest' tag from 'master'") {
when {
branch 'master'
}
steps{
// qe-pipeline-library step
tagRemoteContainerImage(
credentialsId: "${env.CREDENTIALS_ID}",
sourceImage: "${env.OPERATOR_CONTAINER_IMAGE_NAME}",
targetImage: "${env.OPERATOR_CONTAINER_IMAGE_NAME_latest}",
deleteOriginalImage: false
)
}
}
}
post {
failure {
mail(
to: '[email protected]',
subject: 'UnifiedPush Operator build failed',
body: "See the pipeline here: ${env.RUN_DISPLAY_URL}"
)
}
}
}