Skip to content

Conversation

@tympanix
Copy link

Implements Container.inside() to execute a closure within an already-running container, mirroring Image.inside() behavior.

Changes

  • WithContainerStep.java: Made Decorator class package-private (was private) to allow reuse by WithRunningContainerStep

  • WithRunningContainerStep.java (NEW): A new step class for running build steps inside an already-running container

    • Takes containerId as required parameter
    • Validates container exists and is running before execution
    • Re-uses WithContainerStep.Decorator for docker exec wrapping
    • Registered as withRunningDockerContainer step
  • Docker.groovy: Added Container.inside(Closure body) method

    • Delegates to withRunningDockerContainer step with the container's ID
  • DockerDSLTest.java:

    • Added containerInside() test for the new functionality
    • Added containerInsideNonExistingContainer() test to validate error handling when using a non-existing container id

Usage

docker.image('httpd:2.4.62').withRun { c ->
    c.inside {
        sh 'cat /usr/local/apache2/conf/extra/httpd-userdir.conf'
    }
    // Container remains running here
}

Testing done

Added two test cases to validate:

  • Executing the inside method on a container object (from withRun) yields an execution context in the already running container
  • Executing the wintRunningDockerContainer with a non-existing container id yields an exception

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

@tympanix tympanix changed the title [JENKINS-68955] Add inside() method to Container class WIP [JENKINS-68955] Add inside() method to Container class Nov 28, 2025
@tympanix tympanix marked this pull request as draft November 28, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant