Skip to content
Permalink
Browse files

[FIXED JENKINS-38242] Add the ability to specify agent parameters (do…

…cker)

* rename args to dockerArgs
* add tests for null/empty dockerArgs
  • Loading branch information...
Peter Leibiger
Peter Leibiger committed Sep 21, 2016
1 parent df6eadd commit 3878f2932d7c912b777ddabca5cf7f8dcc097d74
@@ -46,7 +46,7 @@ public class Agent implements Serializable {
String label

@Whitelisted
String args
String dockerArgs

@Whitelisted
Boolean any
@@ -59,8 +59,8 @@ public class Agent implements Serializable {
if (args.containsKey("label")) {
label = args.get("label")
}
if (args.containsKey("args")) {
this.args = args.get("args")
if (args.containsKey("dockerArgs")) {
this.dockerArgs = args.get("dockerArgs")
}
}

@@ -76,6 +76,6 @@ public class Agent implements Serializable {

// TODO: Rewrite as an extension point and get this by extension discovery, but we knew that already.
public static List<String> agentConfigKeys() {
return ["docker", "label", "args"]
return ["docker", "label", "dockerArgs"]
}
}
@@ -214,7 +214,7 @@ public class ModelInterpreter implements Serializable {
def dockerOrWithout(Agent agent, Closure body) {
if (agent.docker != null) {
return {
script.getProperty("docker").image(agent.docker).inside(agent.args, {
script.getProperty("docker").image(agent.docker).inside(agent.dockerArgs, {
body.call()
})
}
@@ -74,20 +74,18 @@ public void noCheckoutScmInWrongContext() throws Exception {

@Test
public void agentDocker() throws Exception {
assumeDocker();
// Bind mounting /var on OS X doesn't work at the moment
onAllowedOS(PossibleOS.LINUX);
prepRepoWithJenkinsfile("agentDocker");
final WorkflowRun b = agentDocker("agentDocker");
j.assertLogContains("-v /tmp:/tmp -p 80:80", b);
}

assumeDocker();
DumbSlave s = j.createOnlineSlave();
s.setLabelString("docker");
@Test
public void agentDockerWithNullDockerArgs() throws Exception {
agentDocker("agentDockerWithNullDockerArgs");
}

WorkflowRun b = getAndStartBuild();
j.assertBuildStatusSuccess(j.waitForCompletion(b));
j.assertLogContains("[Pipeline] { (foo)", b);
j.assertLogContains("The answer is 42", b);
j.assertLogContains("-v /tmp:/tmp", b);
@Test
public void agentDockerWithEmptyDockerArgs() throws Exception {
agentDocker("agentDockerWithEmptyDockerArgs");
}

@Test
@@ -121,4 +119,21 @@ public void agentNoneWithNode() throws Exception {
j.assertLogContains("[Pipeline] { (foo)", b);
j.assertLogContains("ONSLAVE=true", b);
}

private WorkflowRun agentDocker(final String jenkinsfile) throws Exception {
assumeDocker();
// Bind mounting /var on OS X doesn't work at the moment
onAllowedOS(PossibleOS.LINUX);
prepRepoWithJenkinsfile(jenkinsfile);

assumeDocker();
DumbSlave s = j.createOnlineSlave();
s.setLabelString("docker");

WorkflowRun b = getAndStartBuild();
j.assertBuildStatusSuccess(j.waitForCompletion(b));
j.assertLogContains("[Pipeline] { (foo)", b);
j.assertLogContains("The answer is 42", b);
return b;
}
}
@@ -23,7 +23,7 @@
*/

pipeline {
agent docker:"httpd:2.4.12", args:"-v /tmp:/tmp"
agent docker:"httpd:2.4.12", dockerArgs:"-v /tmp:/tmp -p 80:80"
stages {
stage("foo") {
sh 'cat /usr/local/apache2/conf/extra/httpd-userdir.conf'
@@ -0,0 +1,36 @@
/*
* The MIT License
*
* Copyright (c) 2016, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pipeline {
agent docker:"httpd:2.4.12", dockerArgs:""
stages {
stage("foo") {
sh 'cat /usr/local/apache2/conf/extra/httpd-userdir.conf'
sh 'echo "The answer is 42"'
}
}
}



@@ -0,0 +1,36 @@
/*
* The MIT License
*
* Copyright (c) 2016, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pipeline {
agent docker:"httpd:2.4.12", dockerArgs:null
stages {
stage("foo") {
sh 'cat /usr/local/apache2/conf/extra/httpd-userdir.conf'
sh 'echo "The answer is 42"'
}
}
}



0 comments on commit 3878f29

Please sign in to comment.
You can’t perform that action at this time.