Skip to content

Commit 4227a29

Browse files
author
OpenShift Bot
authored
Merge pull request #11757 from jupierce/jenkins-exec-freestyle-test
Merged by openshift-bot
2 parents 63e3797 + b1ab6a1 commit 4227a29

11 files changed

+176
-53
lines changed

test/extended/builds/forcepull.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ var _ = g.Describe("[LocalNode][builds] forcePull should affect pulling builder
131131
o.Expect(err).NotTo(o.HaveOccurred())
132132
}()
133133

134-
err = exutil.VarSubOnFile(pre, post, varSubSrc, varSubDest)
134+
err = exutil.VarSubOnFile(pre, post, map[string]string{varSubSrc: varSubDest})
135135
o.Expect(err).NotTo(o.HaveOccurred())
136136
err = exutil.CreateResource(post, oc)
137137
o.Expect(err).NotTo(o.HaveOccurred())

test/extended/image_ecosystem/plugin.go

+79-19
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,30 @@ func (j *JenkinsRef) startJob(jobName string) *JobMon {
292292

293293
// Returns the content of a Jenkins job XML file. Instances of the
294294
// 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 {
296298
pre := exutil.FixturePath("testdata", "jenkins-plugin", filename)
297299
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)
299306
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred())
307+
300308
data, err := ioutil.ReadFile(post)
301309
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred())
302310
return string(data)
303311
}
304312

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+
305319
// Returns an XML string defining a Jenkins workflow/pipeline DSL job. Instances of the
306320
// string "PROJECT_NAME" are replaced with the specified namespace.
307321
func (j *JenkinsRef) buildDSLJob(namespace string, scriptLines ...string) (string, error) {
@@ -397,6 +411,28 @@ func findJenkinsPod(oc *exutil.CLI) *kapi.Pod {
397411
return &pods.Items[0]
398412
}
399413

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+
400436
// Designed to match if RSS memory is greater than 500000000 (i.e. > 476MB)
401437
var memoryOverragePattern = regexp.MustCompile(`\s+rss\s+5\d\d\d\d\d\d\d\d`)
402438

@@ -709,23 +745,7 @@ var _ = g.Describe("[image_ecosystem][jenkins][Slow] openshift pipeline plugin",
709745

710746
g.It("jenkins-plugin test exec DSL", func() {
711747

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)
729749
targetContainer := targetPod.Spec.Containers[0]
730750

731751
data, err := j.buildDSLJob(oc.Namespace(),
@@ -756,6 +776,46 @@ var _ = g.Describe("[image_ecosystem][jenkins][Slow] openshift pipeline plugin",
756776
o.Expect(strings.Contains(log, "hello world 6")).To(o.BeTrue())
757777
})
758778

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\nJenkins 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\nJenkins 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+
759819
g.It("jenkins-plugin test multitag", func() {
760820

761821
loadFixture(oc, "multitag-template.json")

test/extended/testdata/forcepull-test.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
"customStrategy": {
2727
"from": {
2828
"kind": "DockerImage",
29-
"name": "SERVICE_REGISTRY_IP/forcepull-extended-test-builder"
29+
"name": "${SERVICE_REGISTRY_IP}/forcepull-extended-test-builder"
3030
},
3131
"env": [
3232
{
3333
"name": "OPENSHIFT_CUSTOM_BUILD_BASE_IMAGE",
34-
"value": "SERVICE_REGISTRY_IP/forcepull-extended-test-builder"
34+
"value": "${SERVICE_REGISTRY_IP}/forcepull-extended-test-builder"
3535
},
3636
{
3737
"name": "BUILD_LOGLEVEL",
@@ -67,7 +67,7 @@
6767
"dockerStrategy": {
6868
"from": {
6969
"kind": "DockerImage",
70-
"name": "SERVICE_REGISTRY_IP/forcepull-extended-test-builder"
70+
"name": "${SERVICE_REGISTRY_IP}/forcepull-extended-test-builder"
7171
},
7272
"env": [
7373
{
@@ -103,7 +103,7 @@
103103
"sourceStrategy": {
104104
"from": {
105105
"kind": "DockerImage",
106-
"name": "SERVICE_REGISTRY_IP/forcepull-extended-test-builder"
106+
"name": "${SERVICE_REGISTRY_IP}/forcepull-extended-test-builder"
107107
},
108108
"env": [
109109
{
@@ -139,12 +139,12 @@
139139
"customStrategy": {
140140
"from": {
141141
"kind": "DockerImage",
142-
"name": "SERVICE_REGISTRY_IP/forcepull-extended-test-builder"
142+
"name": "${SERVICE_REGISTRY_IP}/forcepull-extended-test-builder"
143143
},
144144
"env": [
145145
{
146146
"name": "OPENSHIFT_CUSTOM_BUILD_BASE_IMAGE",
147-
"value": "SERVICE_REGISTRY_IP/forcepull-extended-test-builder"
147+
"value": "${SERVICE_REGISTRY_IP}/forcepull-extended-test-builder"
148148
},
149149
{
150150
"name": "BUILD_LOGLEVEL",
@@ -180,7 +180,7 @@
180180
"dockerStrategy": {
181181
"from": {
182182
"kind": "DockerImage",
183-
"name": "SERVICE_REGISTRY_IP/forcepull-extended-test-builder"
183+
"name": "${SERVICE_REGISTRY_IP}/forcepull-extended-test-builder"
184184
},
185185
"env": [
186186
{
@@ -216,7 +216,7 @@
216216
"sourceStrategy": {
217217
"from": {
218218
"kind": "DockerImage",
219-
"name": "SERVICE_REGISTRY_IP/forcepull-extended-test-builder"
219+
"name": "${SERVICE_REGISTRY_IP}/forcepull-extended-test-builder"
220220
},
221221
"env": [
222222
{

test/extended/testdata/jenkins-plugin/build-job-slave.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@
1717
<com.openshift.jenkins.plugins.pipeline.OpenShiftScaler>
1818
<apiURL>https://openshift.default.svc.cluster.local</apiURL>
1919
<depCfg>frontend</depCfg>
20-
<namespace>PROJECT_NAME</namespace>
20+
<namespace>${PROJECT_NAME}</namespace>
2121
<replicaCount>0</replicaCount>
2222
<authToken></authToken>
2323
</com.openshift.jenkins.plugins.pipeline.OpenShiftScaler>
2424

2525
<com.openshift.jenkins.plugins.pipeline.OpenShiftBuilder>
2626
<apiURL>https://openshift.default.svc.cluster.local</apiURL>
2727
<bldCfg>frontend</bldCfg>
28-
<namespace>PROJECT_NAME</namespace>
28+
<namespace>${PROJECT_NAME}</namespace>
2929
<authToken></authToken>
3030
<followLog>true</followLog>
3131
<checkForTriggeredDeployments>true</checkForTriggeredDeployments>
3232
</com.openshift.jenkins.plugins.pipeline.OpenShiftBuilder>
3333

3434
<com.openshift.jenkins.plugins.pipeline.OpenShiftDeployer>
3535
<apiURL></apiURL>
36-
<namespace>PROJECT_NAME</namespace>
36+
<namespace>${PROJECT_NAME}</namespace>
3737
<authToken></authToken>
3838
<verbose>false</verbose>
3939
<waitTime></waitTime>
@@ -44,13 +44,13 @@
4444
<com.openshift.jenkins.plugins.pipeline.OpenShiftServiceVerifier>
4545
<apiURL>https://openshift.default.svc.cluster.local</apiURL>
4646
<svcName>frontend</svcName>
47-
<namespace>PROJECT_NAME</namespace>
47+
<namespace>${PROJECT_NAME}</namespace>
4848
<authToken></authToken>
4949
</com.openshift.jenkins.plugins.pipeline.OpenShiftServiceVerifier>
5050

5151
<com.openshift.jenkins.plugins.pipeline.OpenShiftImageTagger>
5252
<apiURL>https://openshift.default.svc.cluster.local</apiURL>
53-
<namespace>PROJECT_NAME</namespace>
53+
<namespace>${PROJECT_NAME}</namespace>
5454
<testStream>origin-nodejs-sample</testStream>
5555
<testTag>latest</testTag>
5656
<prodStream>origin-nodejs-sample</prodStream>
@@ -61,7 +61,7 @@
6161
<com.openshift.jenkins.plugins.pipeline.OpenShiftDeploymentVerifier>
6262
<apiURL>https://openshift.default.svc.cluster.local</apiURL>
6363
<depCfg>frontend-prod</depCfg>
64-
<namespace>PROJECT_NAME</namespace>
64+
<namespace>${PROJECT_NAME}</namespace>
6565
<replicaCount>0</replicaCount>
6666
<authToken></authToken>
6767
</com.openshift.jenkins.plugins.pipeline.OpenShiftDeploymentVerifier>

test/extended/testdata/jenkins-plugin/build-job.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515
<com.openshift.jenkins.plugins.pipeline.OpenShiftScaler>
1616
<apiURL>https://openshift.default.svc.cluster.local</apiURL>
1717
<depCfg>frontend</depCfg>
18-
<namespace>PROJECT_NAME</namespace>
18+
<namespace>${PROJECT_NAME}</namespace>
1919
<replicaCount>0</replicaCount>
2020
<authToken></authToken>
2121
</com.openshift.jenkins.plugins.pipeline.OpenShiftScaler>
2222

2323
<com.openshift.jenkins.plugins.pipeline.OpenShiftBuilder>
2424
<apiURL>https://openshift.default.svc.cluster.local</apiURL>
2525
<bldCfg>frontend</bldCfg>
26-
<namespace>PROJECT_NAME</namespace>
26+
<namespace>${PROJECT_NAME}</namespace>
2727
<authToken></authToken>
2828
<followLog>true</followLog>
2929
<checkForTriggeredDeployments>true</checkForTriggeredDeployments>
3030
</com.openshift.jenkins.plugins.pipeline.OpenShiftBuilder>
3131

3232
<com.openshift.jenkins.plugins.pipeline.OpenShiftDeployer>
3333
<apiURL></apiURL>
34-
<namespace>PROJECT_NAME</namespace>
34+
<namespace>${PROJECT_NAME}</namespace>
3535
<authToken></authToken>
3636
<verbose>false</verbose>
3737
<waitTime></waitTime>
@@ -42,13 +42,13 @@
4242
<com.openshift.jenkins.plugins.pipeline.OpenShiftServiceVerifier>
4343
<apiURL>https://openshift.default.svc.cluster.local</apiURL>
4444
<svcName>frontend</svcName>
45-
<namespace>PROJECT_NAME</namespace>
45+
<namespace>${PROJECT_NAME}</namespace>
4646
<authToken></authToken>
4747
</com.openshift.jenkins.plugins.pipeline.OpenShiftServiceVerifier>
4848

4949
<com.openshift.jenkins.plugins.pipeline.OpenShiftImageTagger>
5050
<apiURL>https://openshift.default.svc.cluster.local</apiURL>
51-
<namespace>PROJECT_NAME</namespace>
51+
<namespace>${PROJECT_NAME}</namespace>
5252
<testStream>origin-nodejs-sample</testStream>
5353
<testTag>latest</testTag>
5454
<prodStream>origin-nodejs-sample</prodStream>
@@ -59,7 +59,7 @@
5959
<com.openshift.jenkins.plugins.pipeline.OpenShiftDeploymentVerifier>
6060
<apiURL>https://openshift.default.svc.cluster.local</apiURL>
6161
<depCfg>frontend-prod</depCfg>
62-
<namespace>PROJECT_NAME</namespace>
62+
<namespace>${PROJECT_NAME}</namespace>
6363
<replicaCount>0</replicaCount>
6464
<authToken></authToken>
6565
</com.openshift.jenkins.plugins.pipeline.OpenShiftDeploymentVerifier>

test/extended/testdata/jenkins-plugin/build-with-env-job.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<com.openshift.jenkins.plugins.pipeline.OpenShiftBuilder>
1616
<apiURL>https://openshift.default.svc.cluster.local</apiURL>
1717
<bldCfg>frontend</bldCfg>
18-
<namespace>PROJECT_NAME</namespace>
18+
<namespace>${PROJECT_NAME}</namespace>
1919
<authToken></authToken>
2020
<followLog>true</followLog>
2121
<checkForTriggeredDeployments>false</checkForTriggeredDeployments>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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="hudson.scm.NullSCM"/>
16+
<canRoam>true</canRoam>
17+
<disabled>false</disabled>
18+
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
19+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
20+
<triggers/>
21+
<concurrentBuild>false</concurrentBuild>
22+
<builders>
23+
<com.openshift.jenkins.plugins.pipeline.OpenShiftExec plugin="[email protected]">
24+
<apiURL></apiURL>
25+
<namespace>${PROJECT_NAME}</namespace>
26+
<authToken></authToken>
27+
<verbose>true</verbose>
28+
<waitTime>120000</waitTime>
29+
<waitUnit>milli</waitUnit>
30+
<pod>${POD_NAME}</pod>
31+
<container>${CONTAINER_NAME}</container>
32+
<command>echo</command>
33+
</com.openshift.jenkins.plugins.pipeline.OpenShiftExec>
34+
<com.openshift.jenkins.plugins.pipeline.OpenShiftExec plugin="[email protected]">
35+
<apiURL></apiURL>
36+
<namespace>${PROJECT_NAME}</namespace>
37+
<authToken></authToken>
38+
<verbose>true</verbose>
39+
<waitTime>120000</waitTime>
40+
<waitUnit>milli</waitUnit>
41+
<pod>${POD_NAME}</pod>
42+
<container>${CONTAINER_NAME}</container>
43+
<command>echo</command>
44+
<arguments>
45+
<com.openshift.jenkins.plugins.pipeline.Argument>
46+
<value>hello</value>
47+
</com.openshift.jenkins.plugins.pipeline.Argument>
48+
<com.openshift.jenkins.plugins.pipeline.Argument>
49+
<value>world</value>
50+
</com.openshift.jenkins.plugins.pipeline.Argument>
51+
<com.openshift.jenkins.plugins.pipeline.Argument>
52+
<value>1</value>
53+
</com.openshift.jenkins.plugins.pipeline.Argument>
54+
</arguments>
55+
</com.openshift.jenkins.plugins.pipeline.OpenShiftExec>
56+
</builders>
57+
<publishers/>
58+
<buildWrappers/>
59+
</project>

test/extended/testdata/jenkins-plugin/imagestream-scm-dsl-job.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="[email protected]">
1616
<script>node {
1717
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;
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;
2020
}</script>
2121
<sandbox>true</sandbox>
2222
</definition>

0 commit comments

Comments
 (0)