[JENKINS-39746] Add Container.exec to run a command in a running container#79
[JENKINS-39746] Add Container.exec to run a command in a running container#79hogarth-sv wants to merge 1 commit intojenkinsci:masterfrom
Conversation
339446d to
1d316db
Compare
1d316db to
909436e
Compare
| Hexadecimal ID of a running container. | ||
| </p> | ||
| </dd> | ||
| <dt><code>Container.exec([args, command])</code></dt> |
There was a problem hiding this comment.
There is only command, no args, and it is not optional, so I think you meant to write
Container.exec(command)
There was a problem hiding this comment.
@hogarthj I think you should add the args attribute to exec in the same way Image.run does.
| WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
| } | ||
| }); | ||
| story.addStep(new Statement() { |
There was a problem hiding this comment.
Any particular reason you are doing two Jenkins restarts in the middle of this test? It seems gratuitous, since you are not testing resumption of builds.
Just fold these all into one step.
| "node {\n" + | ||
| " writeFile file: 'Dockerfile', text: '# This is a test.\\n\\nFROM alpine\\nRUN chmod u+s /bin/busybox \\nENTRYPOINT [\\\"/bin/ping\\\" ] \\nCMD [\\\"localhost\\\"] \\n'\n" + | ||
| " def built = docker.build 'alpine-entrypoint-test'\n" + | ||
| " echo \"built ${built.id}\"\n" + |
There was a problem hiding this comment.
Why not just put this all into one build? Something along the lines of
node {
// prep…
def built = docker.build 'alpine-entrypoint-test'
def con = built.run()
try {
def r = con.exec('echo 42')
// verify result…
} finally {
con.stop()
}
}| story.j.assertLogContains("the answer is 42", b); | ||
| DockerClient client = new DockerClient(new Launcher.LocalLauncher(StreamTaskListener.NULL), null, null); | ||
| String aetIID = client.inspect(new EnvVars(), "alpine-entrypoint-test", ".Id"); | ||
| Fingerprint f = DockerFingerprints.of(aetIID); |
There was a problem hiding this comment.
Delete all this fingerprint checking; unrelated to the purpose of this test case. I suppose just copied from some older test.
| } | ||
|
|
||
| public String exec(String command) { | ||
| docker.script.sh(script: "docker exec ${id} ${command}", returnStdout: true).trim() |
There was a problem hiding this comment.
This could be
public String exec(String args = '', String command) {
docker.script.sh(script: "docker exec${args != '' ? ' ' + args : ''} ${id} ${command}", returnStdout: true).trim()
}
|
@hogarthj Any update on this? |
|
I am not soliciting any new DSL functions. It is impossible to maintain the ones we already have. |
|
Any update on this? It would be good to have any way to actually run things in a running container without need of start/stop a new container each time... >.< |
|
Any update on this? Or similar feature available in Declarative Pipeline? |
|
Any updates on this? It so ugly to do |
This adds functionality to the Container object to be able to directly execute arbitrary commands in a running docker container.