diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesDeclarativeAgent.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesDeclarativeAgent.java index c7de4d9395..3a65558e96 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesDeclarativeAgent.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesDeclarativeAgent.java @@ -36,8 +36,10 @@ public class KubernetesDeclarativeAgent extends DeclarativeAgent containerTemplates; @@ -128,6 +130,15 @@ public void setNodeSelector(String nodeSelector) { this.nodeSelector = nodeSelector; } + public String getNamespace() { + return namespace; + } + + @DataBoundSetter + public void setNamespace(String namespace) { + this.namespace = namespace; + } + public String getWorkingDir() { return workingDir; } @@ -185,6 +196,15 @@ public void setActiveDeadlineSeconds(int activeDeadlineSeconds) { this.activeDeadlineSeconds = activeDeadlineSeconds; } + public int getSlaveConnectTimeout() { + return slaveConnectTimeout; + } + + @DataBoundSetter + public void setSlaveConnectTimeout(int slaveConnectTimeout) { + this.slaveConnectTimeout = slaveConnectTimeout; + } + public String getYamlFile() { return yamlFile; } @@ -235,12 +255,18 @@ public Map getAsArgs() { if (!StringUtils.isEmpty(nodeSelector)) { argMap.put("nodeSelector", nodeSelector); } + if (!StringUtils.isEmpty(namespace)) { + argMap.put("namespace", namespace); + } if (!StringUtils.isEmpty(workingDir)) { argMap.put("workingDir", workingDir); } if (activeDeadlineSeconds != 0) { argMap.put("activeDeadlineSeconds", activeDeadlineSeconds); } + if (slaveConnectTimeout != 0) { + argMap.put("slaveConnectTimeout", slaveConnectTimeout); + } if (instanceCap > 0) { argMap.put("instanceCap", instanceCap); diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java index 8589d76b19..5519c0d256 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java @@ -442,6 +442,23 @@ public void runWithActiveDeadlineSeconds() throws Exception { r.assertLogNotContains("Hello from container!", b); } + @Test + public void runWithSlaveConnectTimeout() throws Exception { + WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "Deadline"); + p.setDefinition(new CpsFlowDefinition(loadPipelineScript("runWithSlaveConnectTimeout.groovy") + , true)); + WorkflowRun b = p.scheduleBuild2(0).waitForStart(); + assertNotNull(b); + + r.waitForMessage("podTemplate", b); + + PodTemplate timeoutTemplate = cloud.getAllTemplates().stream().filter(x -> x.getLabel() == "runWithSlaveConnectTimeout").findAny().orElse(null); + + assertNotNull(timeoutTemplate); + assertEquals(10, timeoutTemplate.getSlaveConnectTimeout()); + r.assertLogNotContains("Hello from container!", b); + } + @Test public void runInPodWithRetention() throws Exception { deletePods(cloud.connect(), getLabels(cloud, this, name), false); diff --git a/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/runWithSlaveConnectTimeout.groovy b/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/runWithSlaveConnectTimeout.groovy new file mode 100644 index 0000000000..57e56a5a92 --- /dev/null +++ b/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/runWithSlaveConnectTimeout.groovy @@ -0,0 +1,14 @@ +podTemplate(label: 'runWithSlaveConnectTimeout', slaveConnectTimeout: 10, containers: [ + containerTemplate(name: 'busybox', image: 'busybox', ttyEnabled: true, command: '/bin/cat'), +]) { + + node ('runWithSlaveConnectTimeout') { + stage('Run') { + container('busybox') { + sh """ + echo "Hello from container!" + """ + } + } + } +}