-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
Jenkins 2.112
Docker Pipeline 1.15, 1.17
The following Pipeline code produces an error:
def image = docker.image("any_existing_image_eg_alpine") image.inside { sh 'date > /tmp/test.txt' sh 'cat /tmp/test.txt' //works, shows file def fileContents = readFile '/tmp/test.txt' //works echo "Contents: ${fileContents}" //works, shows file echo "Exists: ${fileExists('/tmp/test.txt')}" //FAILS (returns false) archiveArtifacts '/tmp/*.txt' //FAILS the build }
archiveArtifacts always reports that it matched no files (except in $WORKSPACE, see below).
DSL steps in docker summary (what I've tried):
- readFile(): works correctly on files in or out of $WORKSPACE
- writeFile(): works correctly on files in or out of $WORKSPACE
- fileExists(): works correctly only on files in $WORKSPACE (auto-mounted volume)
- archiveArtifacts(): archives only files in $WORKSPACE (auto-mounted volume)
So I guess there is a pattern ... and yet the behavior is inconsistent. I could not find any documentation that explains what the rules are.
UPDATE: readFile() now throws NoSuchFileException (docker-pipeline 1.17 and pipeline-basic-steps 2.7) for files outside the workspace, which is probably better.
Workaround is to first copy the necessary files to the $WORKSPACE that is automatically mounted in the container, or to just do everything in the mounted directory in the first place.