Skip to content

Commit 76dc98f

Browse files
author
OpenShift Bot
authored
Merge pull request #11537 from csrwng/jenkins-plugin-scm-tests
Merged by openshift-bot
2 parents eb597fe + a688bed commit 76dc98f

File tree

5 files changed

+128
-2
lines changed

5 files changed

+128
-2
lines changed

test/extended/image_ecosystem/plugin.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"io/ioutil"
99
"net/http"
10+
"net/url"
1011
"regexp"
1112
"strings"
1213
"time"
@@ -770,6 +771,46 @@ var _ = g.Describe("[image_ecosystem][jenkins][Slow] openshift pipeline plugin",
770771

771772
})
772773

774+
testImageStreamSCM := func(jobXMLFile string) {
775+
jobName := "test-imagestream-scm"
776+
g.By("creating a jenkins job with an imagestream SCM")
777+
data := j.readJenkinsJob(jobXMLFile, oc.Namespace())
778+
j.createItem(jobName, data)
779+
780+
// Because polling is enabled, a job should start automatically and fail
781+
// Wait for it to run and fail
782+
tree := url.QueryEscape("jobs[name,color]")
783+
xpath := url.QueryEscape("//job/name[text()='test-imagestream-scm']/../color")
784+
jobStatusURI := "api/xml?tree=%s&xpath=%s"
785+
g.By("waiting for initial job to complete")
786+
wait.Poll(10*time.Second, 10*time.Minute, func() (bool, error) {
787+
result, status, err := j.getResource(jobStatusURI, tree, xpath)
788+
o.Expect(err).NotTo(o.HaveOccurred())
789+
if status == 200 && strings.Contains(result, "red") {
790+
return true, nil
791+
}
792+
return false, nil
793+
})
794+
795+
// Create a new imagestream tag and expect a job to be kicked off
796+
// that will create a new tag in the current namespace
797+
g.By("creating an imagestream tag in the current project")
798+
oc.Run("tag").Args("openshift/jenkins:latest", fmt.Sprintf("%s/testimage:v1", oc.Namespace())).Execute()
799+
800+
// Wait after the image has been tagged for the Jenkins job to run
801+
// and create the new imagestream/tag
802+
g.By("verifying that the job ran by looking for the resulting imagestream tag")
803+
err := exutil.TimedWaitForAnImageStreamTag(oc, oc.Namespace(), "localjenkins", "develop", 10*time.Minute)
804+
o.Expect(err).NotTo(o.HaveOccurred())
805+
}
806+
807+
g.It("jenkins-plugin test imagestream SCM", func() {
808+
testImageStreamSCM("imagestream-scm-job.xml")
809+
})
810+
811+
g.It("jenkins-plugin test imagestream SCM DSL", func() {
812+
testImageStreamSCM("imagestream-scm-dsl-job.xml")
813+
})
773814
})
774815

775816
})

test/extended/setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function os::test::extended::setup () {
3333
fi
3434

3535
os::util::environment::setup_time_vars
36+
os::util::environment::setup_all_server_vars "test-extended/core"
3637

3738
# ensure proper relative directories are set
3839
GINKGO="$(os::build::find-binary ginkgo)"
@@ -58,7 +59,6 @@ function os::test::extended::setup () {
5859
os::log::info "Starting server"
5960

6061
os::util::environment::use_sudo
61-
os::util::environment::setup_all_server_vars "test-extended/core"
6262
os::util::environment::setup_images_vars
6363

6464
local sudo=${USE_SUDO:+sudo}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<flow-definition plugin="[email protected]">
3+
<actions/>
4+
<description></description>
5+
<keepDependencies>false</keepDependencies>
6+
<properties>
7+
<io.fabric8.jenkins.openshiftsync.BuildConfigProjectProperty plugin="[email protected]">
8+
<uid></uid>
9+
<namespace></namespace>
10+
<name></name>
11+
<resourceVersion></resourceVersion>
12+
<contextDir></contextDir>
13+
</io.fabric8.jenkins.openshiftsync.BuildConfigProjectProperty>
14+
</properties>
15+
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="[email protected]">
16+
<script>node {
17+
stage &apos;Stage 1&apos;
18+
openshiftImageStream name: &apos;testimage&apos;, tag: &apos;v1&apos;, namespace: &apos;PROJECT_NAME&apos;
19+
openshiftTag destStream: &apos;localjenkins&apos;, destTag: &apos;develop&apos;, destinationNamespace: &apos;PROJECT_NAME&apos;, namespace: &apos;openshift&apos;, srcStream: &apos;jenkins&apos;, srcTag: &apos;latest&apos;
20+
}</script>
21+
<sandbox>true</sandbox>
22+
</definition>
23+
<triggers>
24+
<hudson.triggers.SCMTrigger>
25+
<spec>* * * * *</spec>
26+
<ignorePostCommitHooks>false</ignorePostCommitHooks>
27+
</hudson.triggers.SCMTrigger>
28+
</triggers>
29+
</flow-definition>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<project>
3+
<actions/>
4+
<description></description>
5+
<keepDependencies>false</keepDependencies>
6+
<properties>
7+
<io.fabric8.jenkins.openshiftsync.BuildConfigProjectProperty plugin="[email protected]">
8+
<uid></uid>
9+
<namespace></namespace>
10+
<name></name>
11+
<resourceVersion></resourceVersion>
12+
<contextDir></contextDir>
13+
</io.fabric8.jenkins.openshiftsync.BuildConfigProjectProperty>
14+
</properties>
15+
<scm class="com.openshift.jenkins.plugins.pipeline.OpenShiftImageStreams" plugin="[email protected]">
16+
<imageStreamName>testimage</imageStreamName>
17+
<tag>v1</tag>
18+
<apiURL></apiURL>
19+
<namespace>PROJECT_NAME</namespace>
20+
<authToken></authToken>
21+
</scm>
22+
<canRoam>true</canRoam>
23+
<disabled>false</disabled>
24+
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
25+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
26+
<triggers>
27+
<hudson.triggers.SCMTrigger>
28+
<spec>* * * * *</spec>
29+
<ignorePostCommitHooks>false</ignorePostCommitHooks>
30+
</hudson.triggers.SCMTrigger>
31+
</triggers>
32+
<concurrentBuild>false</concurrentBuild>
33+
<builders>
34+
<com.openshift.jenkins.plugins.pipeline.OpenShiftImageTagger plugin="[email protected]">
35+
<apiURL></apiURL>
36+
<namespace>openshift</namespace>
37+
<authToken></authToken>
38+
<verbose>false</verbose>
39+
<testTag>latest</testTag>
40+
<prodTag>develop</prodTag>
41+
<testStream>jenkins</testStream>
42+
<prodStream>localjenkins</prodStream>
43+
<destinationNamespace>PROJECT_NAME</destinationNamespace>
44+
<destinationAuthToken></destinationAuthToken>
45+
<alias>false</alias>
46+
</com.openshift.jenkins.plugins.pipeline.OpenShiftImageTagger>
47+
</builders>
48+
<publishers/>
49+
<buildWrappers/>
50+
</project>

test/extended/util/framework.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,14 @@ func WaitForAnImageStream(client client.ImageStreamInterface,
555555
}
556556

557557
// WaitForAnImageStreamTag waits until an image stream with given name has non-empty history for given tag.
558+
// Defaults to waiting for 60 seconds
558559
func WaitForAnImageStreamTag(oc *CLI, namespace, name, tag string) error {
559-
waitTimeout := time.Second * 60
560+
return TimedWaitForAnImageStreamTag(oc, namespace, name, tag, time.Second*60)
561+
}
562+
563+
// TimedWaitForAnImageStreamTag waits until an image stream with given name has non-empty history for given tag.
564+
// Gives up waiting after the specified waitTimeout
565+
func TimedWaitForAnImageStreamTag(oc *CLI, namespace, name, tag string, waitTimeout time.Duration) error {
560566
g.By(fmt.Sprintf("waiting for an is importer to import a tag %s into a stream %s", tag, name))
561567
start := time.Now()
562568
c := make(chan error)

0 commit comments

Comments
 (0)