Skip to content

Commit

Permalink
Merge pull request #58 from cachavezley/master
Browse files Browse the repository at this point in the history
[JENKINS-36332] Allow a command argument to be passed to Image.withRun
  • Loading branch information
jglick committed Sep 7, 2016
2 parents 5f729d7 + 68f0b72 commit 668cfa3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Expand Up @@ -139,9 +139,9 @@ class Docker implements Serializable {
}
}

public <V> V withRun(String args = '', Closure<V> body) {
public <V> V withRun(String args = '', String command = "", Closure<V> body) {
docker.node {
Container c = run(args)
Container c = run(args, command)
try {
body.call(c)
} finally {
Expand Down
Expand Up @@ -65,7 +65,7 @@
Records a run fingerprint in the build.
</p>
</dd>
<dt><code>Image.withRun[(args)] {…}</code></dt>
<dt><code>Image.withRun[(args[, command])] {…}</code></dt>
<dd>
<p>
Like <code>run</code> but stops the container as soon as its body exits, so you do not need a <code>try</code>-<code>finally</code> block.
Expand Down
Expand Up @@ -224,6 +224,26 @@ private static void grep(File dir, String text, String prefix, Set<String> match
});
}

@Test public void withRunCommand() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
assumeDocker();
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
p.setDefinition(new CpsFlowDefinition(
" docker.image('maven:3.3.9-jdk-8').withRun(\"--entrypoint mvn\", \"-version\") {c ->\n" +
" sh \"docker logs ${c.id}\"" +
"}", true));
story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
DockerClient client = new DockerClient(new Launcher.LocalLauncher(StreamTaskListener.NULL), null, null);
String mavenIID = client.inspect(new EnvVars(), "maven:3.3.9-jdk-8", ".Id");
Fingerprint f = DockerFingerprints.of(mavenIID);
assertNotNull(f);
DockerRunFingerprintFacet facet = f.getFacet(DockerRunFingerprintFacet.class);
assertNotNull(facet);
}
});
}

@Test public void build() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
Expand Down

0 comments on commit 668cfa3

Please sign in to comment.