-
Notifications
You must be signed in to change notification settings - Fork 13
/
Jenkinsfile
228 lines (222 loc) · 5.58 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
#!/usr/bin/env groovy
def tested_files = "build/.*|deploy/.*|roles/.*|tests/smoketest/.*|Makefile|watches.yaml|Jenkinsfile"
// can't just use BUILD_TAG because qdr operator limits name of resources to 60 chars
def namespace = env.JOB_BASE_NAME + '-' + env.BUILD_NUMBER
namespace = namespace.toLowerCase()
namespace = namespace.replaceAll('\\.', '-')
def stf_resource = """
apiVersion: infra.watch/v1beta1
kind: ServiceTelemetry
metadata:
name: default
namespace: ${namespace}
spec:
observabilityStrategy: use_redhat
alerting:
alertmanager:
storage:
strategy: ephemeral
receivers:
snmpTraps:
enabled: true
backends:
events:
elasticsearch:
enabled: true
storage:
strategy: ephemeral
metrics:
prometheus:
enabled: true
storage:
strategy: ephemeral
transports:
qdr:
enabled: true
deploymentSize: 1
web:
enabled: false
elasticsearchManifest: |
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: elasticsearch
namespace: $namespace
spec:
version: 7.16.1
volumeClaimDeletePolicy: DeleteOnScaledownAndClusterDeletion
http:
tls:
certificate:
secretName: 'elasticsearch-es-cert'
nodeSets:
- config:
node.roles:
- master
- data
- ingest
node.store.allow_mmap: true
count: 1
name: default
podTemplate:
metadata:
labels:
tuned.openshift.io/elasticsearch: elasticsearch
spec:
containers:
- name: elasticsearch
resources:
limits:
cpu: '2'
memory: 2Gi
requests:
cpu: '1'
memory: 1Gi
volumes:
- emptyDir: {}
name: elasticsearch-data
"""
def working_branch = "master"
pipeline {
agent {
kubernetes {
inheritFrom 'ocp-agent'
defaultContainer 'exec'
}
}
environment {
run_ci = sh(script: "git fetch origin ${env.CHANGE_TARGET} && git diff --name-only origin/${env.CHANGE_TARGET} | egrep \"${tested_files}\"", returnStatus: true)
}
stages {
stage('Clone Upstream') {
when {
environment name: 'run_ci', value: '0'
}
steps {
dir('service-telemetry-operator') {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
checkout scm
script {
working_branch = sh(script: 'git ls-remote --heads origin | grep $(git rev-parse HEAD) | cut -d / -f 3-', returnStdout: true).toString().trim()
if (!working_branch) {
// in this case, a merge with the base branch was required thus we use the second to last commit
// to find the original topic branch name
working_branch = sh(script: 'git ls-remote --heads origin | grep $(git rev-parse HEAD~1) | cut -d / -f 3-', returnStdout: true).toString().trim()
}
}
sh "git checkout -b ${working_branch}"
}
}
}
}
stage('Create project') {
when {
environment name: 'run_ci', value: '0'
expression {
currentBuild.result == null
}
}
steps {
dir('service-telemetry-operator') {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
script {
openshift.withCluster() {
openshift.newProject(namespace)
}
}
}
}
}
}
stage('Build STF Containers') {
when {
environment name: 'run_ci', value: '0'
expression {
currentBuild.result == null
}
}
steps {
dir('service-telemetry-operator') {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
ansiColor('xterm') {
ansiblePlaybook(
playbook: 'build/run-ci.yaml',
colorized: true,
extraVars: [
"namespace": namespace,
"__deploy_stf": "false",
"__local_build_enabled": "true",
"__service_telemetry_snmptraps_enabled": "true",
"__service_telemetry_storage_ephemeral_enabled": "true",
"working_branch":"${working_branch}"
]
)
}
}
}
}
}
stage('Deploy STF Object') {
when {
environment name: 'run_ci', value: '0'
expression {
currentBuild.result == null
}
}
steps {
dir('service-telemetry-operator') {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
script {
openshift.withCluster() {
openshift.withProject(namespace) {
timeout(time: 800, unit: 'SECONDS') {
openshift.create(stf_resource)
sh "OCP_PROJECT=${namespace} VALIDATION_SCOPE=use_redhat ./build/validate_deployment.sh"
}
}
}
}
}
}
}
}
stage('Run Smoketest') {
when {
environment name: 'run_ci', value: '0'
expression {
currentBuild.result == null
}
}
steps {
dir('service-telemetry-operator') {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh "OCP_PROJECT=${namespace} ./tests/smoketest/smoketest.sh"
}
}
}
}
stage('Cleanup') {
when {
environment name: 'run_ci', value: '0'
}
steps {
dir('service-telemetry-operator') {
script {
openshift.withCluster(){
openshift.selector("project/${namespace}").delete()
}
}
}
}
post {
always {
script {
if ( currentBuild.result != null && currentBuild.result != 'SUCCESS' ) {
currentBuild.result = 'FAILURE'
}
}
}
}
}
}
}