forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.go
671 lines (576 loc) · 24.7 KB
/
pipeline.go
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
package builds
import (
"bytes"
"errors"
"fmt"
"net/http"
"net/url"
"os"
"os/exec"
"strings"
"time"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
buildapi "github.com/openshift/origin/pkg/build/apis/build"
exutil "github.com/openshift/origin/test/extended/util"
"github.com/openshift/origin/test/extended/util/jenkins"
)
const (
localClientPluginSnapshotImageStream = "jenkins-client-plugin-snapshot-test"
localClientPluginSnapshotImage = "openshift/" + localClientPluginSnapshotImageStream + ":latest"
localSyncPluginSnapshotImageStream = "jenkins-sync-plugin-snapshot-test"
localSyncPluginSnapshotImage = "openshift/" + localSyncPluginSnapshotImageStream + ":latest"
clientLicenseText = "About OpenShift Client Jenkins Plugin"
syncLicenseText = "About OpenShift Sync"
clientPluginName = "openshift-client"
syncPluginName = "openshift-sync"
)
func debugAnyJenkinsFailure(br *exutil.BuildResult, name string, oc *exutil.CLI, dumpMaster bool) {
if !br.BuildSuccess {
br.LogDumper = jenkins.DumpLogs
fmt.Fprintf(g.GinkgoWriter, "\n\n START debugAnyJenkinsFailure\n\n")
j := jenkins.NewRef(oc)
jobLog, err := j.GetJobConsoleLogsAndMatchViaBuildResult(br, "")
if err == nil {
fmt.Fprintf(g.GinkgoWriter, "\n %s job log:\n%s", name, jobLog)
} else {
fmt.Fprintf(g.GinkgoWriter, "\n error getting %s job log: %#v", name, err)
}
if dumpMaster {
exutil.DumpApplicationPodLogs("jenkins", oc)
}
fmt.Fprintf(g.GinkgoWriter, "\n\n END debugAnyJenkinsFailure\n\n")
}
}
var _ = g.Describe("[Feature:Builds][Slow] openshift pipeline build", func() {
defer g.GinkgoRecover()
var (
jenkinsTemplatePath = exutil.FixturePath("..", "..", "examples", "jenkins", "jenkins-ephemeral-template.json")
mavenSlavePipelinePath = exutil.FixturePath("..", "..", "examples", "jenkins", "pipeline", "maven-pipeline.yaml")
//orchestrationPipelinePath = exutil.FixturePath("..", "..", "examples", "jenkins", "pipeline", "mapsapp-pipeline.yaml")
blueGreenPipelinePath = exutil.FixturePath("..", "..", "examples", "jenkins", "pipeline", "bluegreen-pipeline.yaml")
clientPluginPipelinePath = exutil.FixturePath("..", "..", "examples", "jenkins", "pipeline", "openshift-client-plugin-pipeline.yaml")
envVarsPipelinePath = exutil.FixturePath("testdata", "samplepipeline-withenvs.yaml")
configMapPodTemplatePath = exutil.FixturePath("testdata", "config-map-jenkins-slave-pods.yaml")
imagestreamPodTemplatePath = exutil.FixturePath("testdata", "imagestream-jenkins-slave-pods.yaml")
imagestreamtagPodTemplatePath = exutil.FixturePath("testdata", "imagestreamtag-jenkins-slave-pods.yaml")
podTemplateSlavePipelinePath = exutil.FixturePath("testdata", "jenkins-slave-template.yaml")
oc = exutil.NewCLI("jenkins-pipeline", exutil.KubeConfigPath())
ticker *time.Ticker
j *jenkins.JenkinsRef
dcLogFollow *exec.Cmd
dcLogStdOut, dcLogStdErr *bytes.Buffer
setupJenkins = func() {
// Deploy Jenkins
// NOTE, we use these tests for both a) nightly regression runs against the latest openshift jenkins image on docker hub, and
// b) PR testing for changes to the various openshift jenkins plugins we support. With scenario b), a docker image that extends
// our jenkins image is built, where the proposed plugin change is injected, overwritting the current released version of the plugin.
// Our test/PR jobs on ci.openshift create those images, as well as set env vars this test suite looks for. When both the env var
// and test image is present, a new image stream is created using the test image, and our jenkins template is instantiated with
// an override to use that images stream and test image
var licensePrefix, pluginName string
useSnapshotImage := false
// our pipeline jobs, between jenkins and oc invocations, need more mem than the default
newAppArgs := []string{"-f", jenkinsTemplatePath, "-p", "MEMORY_LIMIT=2Gi"}
clientPluginNewAppArgs, useClientPluginSnapshotImage := jenkins.SetupSnapshotImage(jenkins.UseLocalClientPluginSnapshotEnvVarName, localClientPluginSnapshotImage, localClientPluginSnapshotImageStream, newAppArgs, oc)
syncPluginNewAppArgs, useSyncPluginSnapshotImage := jenkins.SetupSnapshotImage(jenkins.UseLocalSyncPluginSnapshotEnvVarName, localSyncPluginSnapshotImage, localSyncPluginSnapshotImageStream, newAppArgs, oc)
switch {
case useClientPluginSnapshotImage && useSyncPluginSnapshotImage:
fmt.Fprintf(g.GinkgoWriter,
"\nBOTH %s and %s for PR TESTING ARE SET. WILL NOT CHOOSE BETWEEN THE TWO SO TESTING CURRENT PLUGIN VERSIONS IN LATEST OPENSHIFT JENKINS IMAGE ON DOCKER HUB.\n",
jenkins.UseLocalClientPluginSnapshotEnvVarName, jenkins.UseLocalSyncPluginSnapshotEnvVarName)
case useClientPluginSnapshotImage:
fmt.Fprintf(g.GinkgoWriter, "\nTHE UPCOMING TESTS WILL LEVERAGE AN IMAGE THAT EXTENDS THE LATEST OPENSHIFT JENKINS IMAGE AND OVERRIDES THE OPENSHIFT CLIENT PLUGIN WITH A NEW VERSION BUILT FROM PROPOSED CHANGES TO THAT PLUGIN.\n")
licensePrefix = clientLicenseText
pluginName = clientPluginName
useSnapshotImage = true
newAppArgs = clientPluginNewAppArgs
case useSyncPluginSnapshotImage:
fmt.Fprintf(g.GinkgoWriter, "\nTHE UPCOMING TESTS WILL LEVERAGE AN IMAGE THAT EXTENDS THE LATEST OPENSHIFT JENKINS IMAGE AND OVERRIDES THE OPENSHIFT SYNC PLUGIN WITH A NEW VERSION BUILT FROM PROPOSED CHANGES TO THAT PLUGIN.\n")
licensePrefix = syncLicenseText
pluginName = syncPluginName
useSnapshotImage = true
newAppArgs = syncPluginNewAppArgs
default:
fmt.Fprintf(g.GinkgoWriter, "\nNO PR TEST ENV VARS SET SO TESTING CURRENT PLUGIN VERSIONS IN LATEST OPENSHIFT JENKINS IMAGE ON DOCKER HUB.\n")
}
g.By(fmt.Sprintf("calling oc new-app useSnapshotImage %v with license text %s and newAppArgs %#v", useSnapshotImage, licensePrefix, newAppArgs))
err := oc.Run("new-app").Args(newAppArgs...).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("waiting for jenkins deployment")
err = exutil.WaitForDeploymentConfig(oc.KubeClient(), oc.AppsClient().Apps(), oc.Namespace(), "jenkins", 1, oc)
o.Expect(err).NotTo(o.HaveOccurred())
j = jenkins.NewRef(oc)
g.By("wait for jenkins to come up")
_, err = j.WaitForContent("", 200, 10*time.Minute, "")
if err != nil {
exutil.DumpApplicationPodLogs("jenkins", oc)
}
o.Expect(err).NotTo(o.HaveOccurred())
if useSnapshotImage {
g.By("verifying the test image is being used")
// for the test image, confirm that a snapshot version of the plugin is running in the jenkins image we'll test against
_, err = j.WaitForContent(licensePrefix+` ([0-9\.]+)-SNAPSHOT`, 200, 10*time.Minute, "/pluginManager/plugin/"+pluginName+"/thirdPartyLicenses")
o.Expect(err).NotTo(o.HaveOccurred())
}
// Start capturing logs from this deployment config.
// This command will terminate if the Jenkins instance crashes. This
// ensures that even if the Jenkins DC restarts, we should capture
// logs from the crash.
dcLogFollow, dcLogStdOut, dcLogStdErr, err = oc.Run("logs").Args("-f", "dc/jenkins").Background()
o.Expect(err).NotTo(o.HaveOccurred())
}
)
g.Context("Pipeline with maven slave", func() {
g.BeforeEach(func() {
setupJenkins()
if os.Getenv(jenkins.EnableJenkinsMemoryStats) != "" {
ticker = jenkins.StartJenkinsMemoryTracking(oc, oc.Namespace())
}
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeClient().Core().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
})
g.AfterEach(func() {
if g.CurrentGinkgoTestDescription().Failed {
exutil.DumpPodStates(oc)
exutil.DumpPodLogsStartingWith("", oc)
}
if os.Getenv(jenkins.EnableJenkinsMemoryStats) != "" {
ticker.Stop()
}
})
g.It("should build and complete successfully", func() {
// instantiate the template
g.By(fmt.Sprintf("calling oc new-app -f %q", mavenSlavePipelinePath))
err := oc.Run("new-app").Args("-f", mavenSlavePipelinePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
// start the build
g.By("starting the pipeline build and waiting for it to complete")
br, err := exutil.StartBuildAndWait(oc, "openshift-jee-sample")
if err != nil || !br.BuildSuccess {
exutil.DumpBuilds(oc)
exutil.DumpPodLogsStartingWith("maven", oc)
exutil.DumpBuildLogs("openshift-jee-sample-docker", oc)
exutil.DumpDeploymentLogs("openshift-jee-sample", 1, oc)
}
debugAnyJenkinsFailure(br, oc.Namespace()+"-openshift-jee-sample", oc, true)
br.AssertSuccess()
// wait for the service to be running
g.By("expecting the openshift-jee-sample service to be deployed and running")
_, err = exutil.GetEndpointAddress(oc, "openshift-jee-sample")
o.Expect(err).NotTo(o.HaveOccurred())
})
})
g.Context("Pipeline using config map slave", func() {
g.BeforeEach(func() {
setupJenkins()
if os.Getenv(jenkins.EnableJenkinsMemoryStats) != "" {
ticker = jenkins.StartJenkinsMemoryTracking(oc, oc.Namespace())
}
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeClient().Core().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
})
g.AfterEach(func() {
if g.CurrentGinkgoTestDescription().Failed {
exutil.DumpPodStates(oc)
exutil.DumpPodLogsStartingWith("", oc)
}
if os.Getenv(jenkins.EnableJenkinsGCStats) != "" {
g.By("stopping jenkins gc tracking")
ticker.Stop()
}
})
g.It("should build and complete successfully", func() {
g.By("create the pod template with config map")
err := oc.Run("create").Args("-f", configMapPodTemplatePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("calling oc new-app -f %q", podTemplateSlavePipelinePath))
err = oc.Run("new-app").Args("-f", podTemplateSlavePipelinePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting the pipeline build and waiting for it to complete")
br, err := exutil.StartBuildAndWait(oc, "openshift-jee-sample")
if err != nil || !br.BuildSuccess {
exutil.DumpBuilds(oc)
}
debugAnyJenkinsFailure(br, oc.Namespace()+"-openshift-jee-sample", oc, true)
br.AssertSuccess()
g.By("getting job log, make sure has success message")
out, err := j.GetJobConsoleLogsAndMatchViaBuildResult(br, "Finished: SUCCESS")
o.Expect(err).NotTo(o.HaveOccurred())
g.By("making sure job log ran with our config map slave pod template")
o.Expect(out).To(o.ContainSubstring("Running on jenkins-slave"))
})
})
g.Context("Pipeline using imagestream slave", func() {
g.BeforeEach(func() {
setupJenkins()
if os.Getenv(jenkins.EnableJenkinsMemoryStats) != "" {
ticker = jenkins.StartJenkinsMemoryTracking(oc, oc.Namespace())
}
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeClient().Core().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
})
g.AfterEach(func() {
if g.CurrentGinkgoTestDescription().Failed {
exutil.DumpPodStates(oc)
exutil.DumpPodLogsStartingWith("", oc)
}
if os.Getenv(jenkins.EnableJenkinsGCStats) != "" {
g.By("stopping jenkins gc tracking")
ticker.Stop()
}
})
g.It("should build and complete successfully", func() {
g.By("create the pod template with imagestream")
err := oc.Run("create").Args("-f", imagestreamPodTemplatePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("calling oc new-app -f %q", podTemplateSlavePipelinePath))
err = oc.Run("new-app").Args("-f", podTemplateSlavePipelinePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting the pipeline build and waiting for it to complete")
br, err := exutil.StartBuildAndWait(oc, "openshift-jee-sample")
if err != nil || !br.BuildSuccess {
exutil.DumpBuilds(oc)
}
debugAnyJenkinsFailure(br, oc.Namespace()+"-openshift-jee-sample", oc, true)
br.AssertSuccess()
g.By("getting job log, making sure job log has success message")
out, err := j.GetJobConsoleLogsAndMatchViaBuildResult(br, "Finished: SUCCESS")
o.Expect(err).NotTo(o.HaveOccurred())
g.By("making sure job log ran with our config map slave pod template")
o.Expect(out).To(o.ContainSubstring("Running on jenkins-slave"))
})
})
g.Context("Pipeline using imagestreamtag slave", func() {
g.BeforeEach(func() {
setupJenkins()
if os.Getenv(jenkins.EnableJenkinsMemoryStats) != "" {
ticker = jenkins.StartJenkinsMemoryTracking(oc, oc.Namespace())
}
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeClient().Core().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
})
g.AfterEach(func() {
if g.CurrentGinkgoTestDescription().Failed {
exutil.DumpPodStates(oc)
exutil.DumpPodLogsStartingWith("", oc)
}
if os.Getenv(jenkins.EnableJenkinsGCStats) != "" {
g.By("stopping jenkins gc tracking")
ticker.Stop()
}
})
g.It("should build and complete successfully", func() {
g.By("create the pod template with imagestream")
err := oc.Run("create").Args("-f", imagestreamtagPodTemplatePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("calling oc new-app -f %q", podTemplateSlavePipelinePath))
err = oc.Run("new-app").Args("-f", podTemplateSlavePipelinePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting the pipeline build and waiting for it to complete")
br, err := exutil.StartBuildAndWait(oc, "openshift-jee-sample")
if err != nil || !br.BuildSuccess {
exutil.DumpBuilds(oc)
}
debugAnyJenkinsFailure(br, oc.Namespace()+"-openshift-jee-sample", oc, true)
br.AssertSuccess()
g.By("getting job log, making sure job log has success message")
out, err := j.GetJobConsoleLogsAndMatchViaBuildResult(br, "Finished: SUCCESS")
o.Expect(err).NotTo(o.HaveOccurred())
g.By("making sure job log ran with our config map slave pod template")
o.Expect(out).To(o.ContainSubstring("Running on slave-jenkins"))
})
})
g.Context("Pipeline using jenkins-client-plugin", func() {
g.BeforeEach(func() {
setupJenkins()
if os.Getenv(jenkins.EnableJenkinsMemoryStats) != "" {
ticker = jenkins.StartJenkinsMemoryTracking(oc, oc.Namespace())
}
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeClient().Core().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
})
g.AfterEach(func() {
if g.CurrentGinkgoTestDescription().Failed {
exutil.DumpPodStates(oc)
exutil.DumpPodLogsStartingWith("", oc)
}
if os.Getenv(jenkins.EnableJenkinsMemoryStats) != "" {
ticker.Stop()
}
})
g.It("should build and complete successfully", func() {
// instantiate the bc
g.By("create the jenkins pipeline strategy build config that leverages openshift client plugin")
err := oc.Run("create").Args("-f", clientPluginPipelinePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
// start the build
g.By("starting the pipeline build and waiting for it to complete")
br, err := exutil.StartBuildAndWait(oc, "sample-pipeline-openshift-client-plugin")
debugAnyJenkinsFailure(br, oc.Namespace()+"-sample-pipeline-openshift-client-plugin", oc, true)
if err != nil || !br.BuildSuccess {
exutil.DumpBuilds(oc)
exutil.DumpBuildLogs("ruby", oc)
exutil.DumpDeploymentLogs("mongodb", 1, oc)
exutil.DumpDeploymentLogs("jenkins-second-deployment", 1, oc)
exutil.DumpDeploymentLogs("jenkins-second-deployment", 2, oc)
}
br.AssertSuccess()
g.By("get build console logs and see if succeeded")
_, err = j.GetJobConsoleLogsAndMatchViaBuildResult(br, "Finished: SUCCESS")
o.Expect(err).NotTo(o.HaveOccurred())
})
})
g.Context("Pipeline with env vars", func() {
g.BeforeEach(func() {
setupJenkins()
if os.Getenv(jenkins.EnableJenkinsMemoryStats) != "" {
ticker = jenkins.StartJenkinsMemoryTracking(oc, oc.Namespace())
}
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeClient().Core().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
})
g.AfterEach(func() {
if g.CurrentGinkgoTestDescription().Failed {
exutil.DumpPodStates(oc)
exutil.DumpPodLogsStartingWith("", oc)
}
if os.Getenv(jenkins.EnableJenkinsMemoryStats) != "" {
ticker.Stop()
}
})
g.It("should build and complete successfully", func() {
// instantiate the bc
g.By(fmt.Sprintf("calling oc new-app -f %q", envVarsPipelinePath))
err := oc.Run("new-app").Args("-f", envVarsPipelinePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
// start the build
g.By("starting the pipeline build, including env var, and waiting for it to complete")
br, err := exutil.StartBuildAndWait(oc, "-e", "FOO2=BAR2", "sample-pipeline-withenvs")
if err != nil || !br.BuildSuccess {
exutil.DumpBuilds(oc)
}
debugAnyJenkinsFailure(br, oc.Namespace()+"-sample-pipeline-withenvs", oc, true)
br.AssertSuccess()
g.By("confirm all the log annotations are there")
_, err = jenkins.ProcessLogURLAnnotations(oc, br)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("get build console logs and see if succeeded")
out, err := j.GetJobConsoleLogsAndMatchViaBuildResult(br, "Finished: SUCCESS")
if err != nil {
exutil.DumpApplicationPodLogs("jenkins", oc)
exutil.DumpBuilds(oc)
}
o.Expect(err).NotTo(o.HaveOccurred())
g.By("and see if env is set")
if !strings.Contains(out, "FOO2 is BAR2") {
exutil.DumpApplicationPodLogs("jenkins", oc)
exutil.DumpBuilds(oc)
o.Expect(out).To(o.ContainSubstring("FOO2 is BAR2"))
}
// start the nextbuild
g.By("starting the pipeline build and waiting for it to complete")
br, err = exutil.StartBuildAndWait(oc, "sample-pipeline-withenvs")
if err != nil || !br.BuildSuccess {
exutil.DumpApplicationPodLogs("jenkins", oc)
exutil.DumpBuilds(oc)
}
debugAnyJenkinsFailure(br, oc.Namespace()+"-sample-pipeline-withenvs", oc, true)
br.AssertSuccess()
g.By("get build console logs and see if succeeded")
out, err = j.GetJobConsoleLogsAndMatchViaBuildResult(br, "Finished: SUCCESS")
if err != nil {
exutil.DumpApplicationPodLogs("jenkins", oc)
exutil.DumpBuilds(oc)
}
o.Expect(err).NotTo(o.HaveOccurred())
g.By("and see if env FOO1 is set")
if !strings.Contains(out, "FOO1 is BAR1") {
exutil.DumpApplicationPodLogs("jenkins", oc)
exutil.DumpBuilds(oc)
o.Expect(out).To(o.ContainSubstring("FOO1 is BAR1"))
}
g.By("and see if env FOO2 is still not set")
if !strings.Contains(out, "FOO2 is null") {
exutil.DumpApplicationPodLogs("jenkins", oc)
exutil.DumpBuilds(oc)
o.Expect(out).To(o.ContainSubstring("FOO2 is null"))
}
})
})
/*g.Context("Orchestration pipeline", func() {
g.BeforeEach(func() {
setupJenkins()
if os.Getenv(jenkins.EnableJenkinsMemoryStats) != "" {
ticker = jenkins.StartJenkinsMemoryTracking(oc, oc.Namespace())
}
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeClient().Core().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
})
g.AfterEach(func() {
if os.Getenv(jenkins.EnableJenkinsGCStats) != "" {
g.By("stopping jenkins gc tracking")
ticker.Stop()
}
})
g.It("should build and complete successfully", func() {
// instantiate the template
g.By(fmt.Sprintf("calling oc new-app -f %q", orchestrationPipelinePath))
err := oc.Run("new-app").Args("-f", orchestrationPipelinePath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
// start the build
g.By("starting the pipeline build and waiting for it to complete")
br, _ := exutil.StartBuildAndWait(oc, "mapsapp-pipeline")
debugAnyJenkinsFailure(br, oc.Namespace()+"-mapsapp-pipeline", oc, true)
debugAnyJenkinsFailure(br, oc.Namespace()+"-mlbparks-pipeline", oc, false)
debugAnyJenkinsFailure(br, oc.Namespace()+"-nationalparks-pipeline", oc, false)
debugAnyJenkinsFailure(br, oc.Namespace()+"-parksmap-pipeline", oc, false)
br.AssertSuccess()
// wait for the service to be running
g.By("expecting the parksmap-web service to be deployed and running")
_, err = exutil.GetEndpointAddress(oc, "parksmap")
o.Expect(err).NotTo(o.HaveOccurred())
})
})*/
g.Context("Blue-green pipeline", func() {
g.BeforeEach(func() {
setupJenkins()
if os.Getenv(jenkins.EnableJenkinsMemoryStats) != "" {
ticker = jenkins.StartJenkinsMemoryTracking(oc, oc.Namespace())
}
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeClient().Core().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
})
g.AfterEach(func() {
if g.CurrentGinkgoTestDescription().Failed {
exutil.DumpPodStates(oc)
exutil.DumpPodLogsStartingWith("", oc)
}
if os.Getenv(jenkins.EnableJenkinsMemoryStats) != "" {
ticker.Stop()
}
})
g.It("Blue-green pipeline should build and complete successfully", func() {
// instantiate the template
g.By(fmt.Sprintf("calling oc new-app -f %q", blueGreenPipelinePath))
err := oc.Run("new-app").Args("-f", blueGreenPipelinePath, "-p", "VERBOSE=true").Execute()
o.Expect(err).NotTo(o.HaveOccurred())
buildAndSwitch := func(newColour string) {
// start the build
g.By("starting the bluegreen pipeline build")
br, err := exutil.StartBuildResult(oc, "bluegreen-pipeline")
if err != nil || !br.BuildSuccess {
debugAnyJenkinsFailure(br, oc.Namespace()+"-bluegreen-pipeline", oc, false)
exutil.DumpBuilds(oc)
}
o.Expect(err).NotTo(o.HaveOccurred())
errs := make(chan error, 2)
stop := make(chan struct{})
go func() {
defer g.GinkgoRecover()
g.By("Waiting for the build uri")
var jenkinsBuildURI string
for {
build, err := oc.BuildClient().Build().Builds(oc.Namespace()).Get(br.BuildName, metav1.GetOptions{})
if err != nil {
errs <- fmt.Errorf("error getting build: %s", err)
return
}
jenkinsBuildURI = build.Annotations[buildapi.BuildJenkinsBuildURIAnnotation]
if jenkinsBuildURI != "" {
break
}
select {
case <-stop:
return
default:
time.Sleep(10 * time.Second)
}
}
url, err := url.Parse(jenkinsBuildURI)
if err != nil {
errs <- fmt.Errorf("error parsing build uri: %s", err)
return
}
jenkinsBuildURI = strings.Trim(url.Path, "/") // trim leading https://host/ and trailing /
g.By("Waiting for the approval prompt")
for {
body, status, err := j.GetResource(jenkinsBuildURI + "/consoleText")
if err == nil && status == http.StatusOK && strings.Contains(body, "Approve?") {
break
}
select {
case <-stop:
return
default:
time.Sleep(10 * time.Second)
}
}
g.By("Approving the current build")
_, _, err = j.Post(nil, jenkinsBuildURI+"/input/Approval/proceedEmpty", "")
if err != nil {
errs <- fmt.Errorf("error approving the current build: %s", err)
}
}()
go func() {
defer g.GinkgoRecover()
for {
build, err := oc.BuildClient().Build().Builds(oc.Namespace()).Get(br.BuildName, metav1.GetOptions{})
switch {
case err != nil:
errs <- fmt.Errorf("error getting build: %s", err)
return
case exutil.CheckBuildFailedFn(build):
errs <- nil
return
case exutil.CheckBuildSuccessFn(build):
br.BuildSuccess = true
errs <- nil
return
}
select {
case <-stop:
return
default:
time.Sleep(5 * time.Second)
}
}
}()
g.By("waiting for the build to complete")
select {
case <-time.After(60 * time.Minute):
err = errors.New("timeout waiting for build to complete")
case err = <-errs:
}
close(stop)
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "error occurred (%s): getting logs before failing\n", err)
}
debugAnyJenkinsFailure(br, oc.Namespace()+"-bluegreen-pipeline", oc, true)
if err != nil || !br.BuildSuccess {
debugAnyJenkinsFailure(br, oc.Namespace()+"-bluegreen-pipeline", oc, false)
exutil.DumpBuilds(oc)
}
br.AssertSuccess()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("verifying that the main route has been switched to %s", newColour))
value, err := oc.Run("get").Args("route", "nodejs-mongodb-example", "-o", "jsonpath={ .spec.to.name }").Output()
o.Expect(err).NotTo(o.HaveOccurred())
activeRoute := strings.TrimSpace(value)
g.By(fmt.Sprintf("verifying that the active route is 'nodejs-mongodb-example-%s'", newColour))
o.Expect(activeRoute).To(o.Equal(fmt.Sprintf("nodejs-mongodb-example-%s", newColour)))
}
buildAndSwitch("green")
buildAndSwitch("blue")
})
})
})