Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-40170

Separate execution functionality of image.inside() into distinct steps

XMLWordPrintable

      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?

            Unassigned Unassigned
            courtarro Ethan Trewhitt
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: