When running a container in my Jenkins CI like this:
image.inside('-v /build:/build:rw') {
body()
}
the default Jenkins workspace, which in my case is /home/jenkins/workspace/kevin
is being mounted to the docker container and any changes made in the container to that directory is being reflected on the host machine. I checked the docker command and I noticed that jenkins is mounting the default workspace inside the container like:
-v /home/jenkins/workspace/kevin:/home/jenkins/workspace/kevin:rw,z
Why? How can I disable mounting the workspace to the container?
When running a container in my Jenkins CI like this:
image.inside('-v /build:/build:rw') {
body()
}
the default Jenkins workspace, which in my case is /home/jenkins/workspace/kevin
is being mounted to the docker container and any changes made in the container to that directory is being reflected on the host machine. I checked the docker command and I noticed that jenkins is mounting the default workspace inside the container like:
-v /home/jenkins/workspace/kevin:/home/jenkins/workspace/kevin:rw,z
Why? How can I disable mounting the workspace to the container?
Share Improve this question asked Mar 20 at 9:40 Kevin NammourKevin Nammour 312 bronze badges1 Answer
Reset to default 0Why?
The mundane answer is because it was invented that way.
Source code: https://github/jenkinsci/docker-workflow-plugin/blob/d3d06101cbc6e96e6d47c4c67517239e05dfafa5/src/main/java//jenkinsci/plugins/docker/workflow/WithContainerStep.java#L19 .
How can I disable mounting the workspace to the container?
sh "docker run ${image.imageName()} stuff"
You should also be able to overwrite the mount, like:
image.inside("-v /tmp:${WORKSPACE} -w / -u root:root")