-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathJenkinsfile
167 lines (155 loc) · 5.31 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
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 = "app-metrics-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 = "app-metrics"
CLONED_REPOSITORY_PATH = "src/github.com/aerogear/app-metrics-operator"
CREDENTIALS_ID = "quay-aerogear-bot"
}
options {
checkoutToSubdirectory("src/github.com/aerogear/app-metrics-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("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("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}",
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: 'App Metrics Operator build failed',
body: "See the pipeline here: ${env.RUN_DISPLAY_URL}"
)
}
}
}