Reputation: 1133
If I have a Jenkinsfile with
docker.image('foo').inside {
writeFile file: bar, text: baz
}
the file gets written to the Jenkins agent's workspace, not inside the container, right? Is there a sane way to write a file inside a container?
The closest thing I was able to find on the web is https://issues.jenkins-ci.org/browse/JENKINS-33510. I suppose I could use a sh
step with a here-doc, but that sounds pretty ugly.
Upvotes: 2
Views: 3722
Reputation: 1316
There is a workspace in the container and you can write files inside the container with writeFiles
.
But it's also shared with the workspace of the host node because it's mounted as a volume.
inside
will:
- Automatically grab a slave and a workspace (no extra node block is required).
- Pull the requested image to the Docker server (if not already cached).
- Start a container running that image.
- Mount the Jenkins workspace as a “volume” inside the container, using the same file path.
You can see more detail what happens in inside
here: https://go.cloudbees.com/docs/cloudbees-documentation/cje-user-guide/chapter-docker-workflow.html
Upvotes: 1