@@ -292,16 +292,30 @@ func (j *JenkinsRef) startJob(jobName string) *JobMon {
292
292
293
293
// Returns the content of a Jenkins job XML file. Instances of the
294
294
// string "PROJECT_NAME" are replaced with the specified namespace.
295
- func (j * JenkinsRef ) readJenkinsJob (filename , namespace string ) string {
295
+ // Variables named in the vars map will also be replaced with their
296
+ // corresponding value.
297
+ func (j * JenkinsRef ) readJenkinsJobUsingVars (filename , namespace string , vars map [string ]string ) string {
296
298
pre := exutil .FixturePath ("testdata" , "jenkins-plugin" , filename )
297
299
post := exutil .ArtifactPath (filename )
298
- err := exutil .VarSubOnFile (pre , post , "PROJECT_NAME" , namespace )
300
+
301
+ if vars == nil {
302
+ vars = map [string ]string {}
303
+ }
304
+ vars ["PROJECT_NAME" ] = namespace
305
+ err := exutil .VarSubOnFile (pre , post , vars )
299
306
o .ExpectWithOffset (1 , err ).NotTo (o .HaveOccurred ())
307
+
300
308
data , err := ioutil .ReadFile (post )
301
309
o .ExpectWithOffset (1 , err ).NotTo (o .HaveOccurred ())
302
310
return string (data )
303
311
}
304
312
313
+ // Returns the content of a Jenkins job XML file. Instances of the
314
+ // string "PROJECT_NAME" are replaced with the specified namespace.
315
+ func (j * JenkinsRef ) readJenkinsJob (filename , namespace string ) string {
316
+ return j .readJenkinsJobUsingVars (filename , namespace , nil )
317
+ }
318
+
305
319
// Returns an XML string defining a Jenkins workflow/pipeline DSL job. Instances of the
306
320
// string "PROJECT_NAME" are replaced with the specified namespace.
307
321
func (j * JenkinsRef ) buildDSLJob (namespace string , scriptLines ... string ) (string , error ) {
@@ -397,6 +411,28 @@ func findJenkinsPod(oc *exutil.CLI) *kapi.Pod {
397
411
return & pods .Items [0 ]
398
412
}
399
413
414
+ // Stands up a simple pod which can be used for exec commands
415
+ func initExecPod (oc * exutil.CLI ) * kapi.Pod {
416
+ // Create a running pod in which we can execute our commands
417
+ oc .Run ("run" ).Args ("centos" , "--image" , "centos:7" , "--command" , "--" , "sleep" , "1800" ).Execute ()
418
+
419
+ var targetPod * kapi.Pod
420
+ err := wait .Poll (10 * time .Second , 10 * time .Minute , func () (bool , error ) {
421
+ pods , err := oc .KubeREST ().Pods (oc .Namespace ()).List (kapi.ListOptions {})
422
+ o .ExpectWithOffset (1 , err ).NotTo (o .HaveOccurred ())
423
+ for _ , p := range pods .Items {
424
+ if strings .HasPrefix (p .Name , "centos" ) && ! strings .Contains (p .Name , "deploy" ) && p .Status .Phase == "Running" {
425
+ targetPod = & p
426
+ return true , nil
427
+ }
428
+ }
429
+ return false , nil
430
+ })
431
+ o .ExpectWithOffset (1 , err ).NotTo (o .HaveOccurred ())
432
+
433
+ return targetPod
434
+ }
435
+
400
436
// Designed to match if RSS memory is greater than 500000000 (i.e. > 476MB)
401
437
var memoryOverragePattern = regexp .MustCompile (`\s+rss\s+5\d\d\d\d\d\d\d\d` )
402
438
@@ -709,23 +745,7 @@ var _ = g.Describe("[image_ecosystem][jenkins][Slow] openshift pipeline plugin",
709
745
710
746
g .It ("jenkins-plugin test exec DSL" , func () {
711
747
712
- // Create a running pod in which we can execute our commands
713
- oc .Run ("new-app" ).Args ("https://github.com/openshift/ruby-hello-world" ).Execute ()
714
-
715
- var targetPod * kapi.Pod
716
- err := wait .Poll (10 * time .Second , 10 * time .Minute , func () (bool , error ) {
717
- pods , err := oc .KubeREST ().Pods (oc .Namespace ()).List (kapi.ListOptions {})
718
- o .Expect (err ).NotTo (o .HaveOccurred ())
719
- for _ , p := range pods .Items {
720
- if ! strings .Contains (p .Name , "build" ) && ! strings .Contains (p .Name , "deploy" ) && p .Status .Phase == "Running" {
721
- targetPod = & p
722
- return true , nil
723
- }
724
- }
725
- return false , nil
726
- })
727
- o .Expect (err ).NotTo (o .HaveOccurred ())
728
-
748
+ targetPod := initExecPod (oc )
729
749
targetContainer := targetPod .Spec .Containers [0 ]
730
750
731
751
data , err := j .buildDSLJob (oc .Namespace (),
@@ -756,6 +776,46 @@ var _ = g.Describe("[image_ecosystem][jenkins][Slow] openshift pipeline plugin",
756
776
o .Expect (strings .Contains (log , "hello world 6" )).To (o .BeTrue ())
757
777
})
758
778
779
+ g .It ("jenkins-plugin test exec freestyle" , func () {
780
+
781
+ targetPod := initExecPod (oc )
782
+ targetContainer := targetPod .Spec .Containers [0 ]
783
+
784
+ jobName := "test-build-with-env-steps"
785
+ data := j .readJenkinsJobUsingVars ("build-with-exec-steps.xml" , oc .Namespace (), map [string ]string {
786
+ "POD_NAME" : targetPod .Name ,
787
+ "CONTAINER_NAME" : targetContainer .Name ,
788
+ })
789
+
790
+ j .createItem (jobName , data )
791
+ jmon := j .startJob (jobName )
792
+ jmon .await (2 * time .Minute )
793
+
794
+ log , err := j .getLastJobConsoleLogs (jobName )
795
+ ginkgolog ("\n \n Jenkins logs>\n %s\n \n " , log )
796
+ o .Expect (err ).NotTo (o .HaveOccurred ())
797
+
798
+ o .Expect (strings .Contains (log , "hello world 1" )).To (o .BeTrue ())
799
+
800
+ // Now run without specifying container
801
+ jobName = "test-build-with-env-steps-no-container"
802
+ data = j .readJenkinsJobUsingVars ("build-with-exec-steps.xml" , oc .Namespace (), map [string ]string {
803
+ "POD_NAME" : targetPod .Name ,
804
+ "CONTAINER_NAME" : "" ,
805
+ })
806
+
807
+ j .createItem (jobName , data )
808
+ jmon = j .startJob (jobName )
809
+ jmon .await (2 * time .Minute )
810
+
811
+ log , err = j .getLastJobConsoleLogs (jobName )
812
+ ginkgolog ("\n \n Jenkins logs>\n %s\n \n " , log )
813
+ o .Expect (err ).NotTo (o .HaveOccurred ())
814
+
815
+ o .Expect (strings .Contains (log , "hello world 1" )).To (o .BeTrue ())
816
+
817
+ })
818
+
759
819
g .It ("jenkins-plugin test multitag" , func () {
760
820
761
821
loadFixture (oc , "multitag-template.json" )
0 commit comments