Skip to content
Permalink
Browse files
Merge pull request #37 from vfarcic/jenkins-33063
[FIXED JENKINS-33063] Allow Image.run() to provide arguments to the container’s command
  • Loading branch information
jglick committed May 4, 2016
2 parents af5a669 + c1dc2e3 commit 153c70d5e863eb499b49d08d6992f3eff3ca586a
@@ -121,9 +121,9 @@ class Docker implements Serializable {
}
}

public Container run(String args = '') {
public Container run(String args = '', String command = "") {
docker.node {
docker.script.sh "docker run -d${args != '' ? ' ' + args : ''} ${id} > .container"
docker.script.sh "docker run -d${args != '' ? ' ' + args : ''} ${id}${command != '' ? ' ' + command : ''} > .container"
def container = docker.script.readFile('.container').trim()
docker.script.dockerFingerprintRun containerId: container, toolName: docker.script.env.DOCKER_TOOL_NAME
new Container(docker, container)
@@ -55,11 +55,12 @@
The image name with optional tag (<code>mycorp/myapp</code>, <code>mycorp/myapp:latest</code>) or ID (hexadecimal hash).
</p>
</dd>
<dt><code>Image.run([args])</code></dt>
<dt><code>Image.run([args, command])</code></dt>
<dd>
<p>
Uses <code>docker run</code> to run the image, and returns a <code>Container</code> which you could <code>stop</code> later.
Additional <code>args</code> may be added, such as <code>'-p 8080:8080 --memory-swap=-1'</code>.
Optional <code>command</code> is equivalent to Docker command specified after the image.
Records a run fingerprint in the build.
</p>
</dd>
@@ -324,4 +324,20 @@ private static void grep(File dir, String text, String prefix, Set<String> match
}
});
}

@Test public void run() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
assumeDocker();
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" def busybox = docker.image('busybox');\n" +
" busybox.run('--rm', 'echo \"Hello\"');\n" +
"}", true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("Hello", b);
}
});
}
}

0 comments on commit 153c70d

Please sign in to comment.