jenkinsci / jenkinsci/docker-workflow-plugin

[JENKINS-40170] Separate execution functionality of image.inside() into distinct steps

Open
#461 2 comments 0 reactions 0 assignees View on GitHub
component:docker-workflow-plugin enhancement imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
527
Forks
422
Avg merge
10m
Merged PRs (30d)
1

Description

Image.inside() performs a number of tasks that are useful in many cases. Unfortunately it also performs one task that cannot directly be performed with any other Groovy step: actually running code in the image. The execution step should be separated from the other steps performed by inside() so that users can control what happens. If this means that inside() remains the same, while a new method is created that only executes code within the running container, that's fine. It's already a bit strange that "inside" is attached to the "Image" object, since the code is actually being executed inside a container instantiated from that image.

May I suggest adding a some functions to the "container" object so that we can do this? I would envision this process to look something like this:

node {

def image = docker.image('metatest')
def container = image.run()
container.execInside() {
step("Get Username") {
sh "whoami"
}
step("Report Success") {
sh "echo Success!"
}
}
container.stop()
container.remove()
}

Note that I have also separated the stop and rm steps for the container. I see no reason why they should be combined in the stop() method. Why not mirror the Docker commands with the same name?

---
Originally reported by courtarro, imported from: Separate execution functionality of image.inside() into distinct steps


  • status: Open
  • priority: Minor
  • component(s): docker-workflow-plugin
  • resolution: Unresolved
  • votes: 3
  • watchers: 6
  • imported: 2025-12-07

Raw content of original issue

Image.inside() performs a number of tasks that are useful in many cases. Unfortunately it also performs one task that cannot directly be performed with any other Groovy step: actually running code in the image. The execution step should be separated from the other steps performed by inside() so that users can control what happens. If this means that inside() remains the same, while a new method is created that only executes code within the running container, that's fine. It's already a bit strange that "inside" is attached to the "Image" object, since the code is actually being executed inside a container instantiated from that image.

May I suggest adding a some functions to the "container" object so that we can do this? I would envision this process to look something like this:


node {

def image = docker.image('metatest')
def container = image.run()
container.execInside() {
step("Get Username") {
sh "whoami"
}
step("Report Success") {
sh "echo Success!"
}
}
container.stop()
container.remove()
}

Note that I have also separated the stop and rm steps for the container. I see no reason why they should be combined in the stop() method. Why not mirror the Docker commands with the same name?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.