-
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.
[JENKINS-51462] archiveArtifacts and fileExists inconsistent in docker.inside() closure
Description |
Original:
The following Pipeline code produces an error: {code:java} def container = docker.image("any_existing_image_eg_alpine") container.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 archiveArtifacts '/tmp/*.txt' //FAILS } {code} No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files. It does not appear to be looking on the docker host either, because '/*' or '*' also match nothing. The interesting thing is that readFile works. |
New:
The following Pipeline code produces an error: {code:java} def container = docker.image("any_existing_image_eg_alpine") container.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 archiveArtifacts '/tmp/*.txt' //FAILS } {code} No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files. It does not appear to be looking on the docker host either, because '/\**' or '**' also match nothing. The interesting thing is that readFile works. |
Description |
Original:
The following Pipeline code produces an error: {code:java} def container = docker.image("any_existing_image_eg_alpine") container.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 archiveArtifacts '/tmp/*.txt' //FAILS } {code} No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files. It does not appear to be looking on the docker host either, because '/\**' or '**' also match nothing. The interesting thing is that readFile works. |
New:
The following Pipeline code produces an error: {code:java} def container = docker.image("any_existing_image_eg_alpine") container.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 archiveArtifacts '/tmp/*.txt' //FAILS } {code} No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files. It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing. The interesting thing is that readFile works. I've even tried using writeFile() to create the file, it made no difference. |
Description |
Original:
The following Pipeline code produces an error: {code:java} def container = docker.image("any_existing_image_eg_alpine") container.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 archiveArtifacts '/tmp/*.txt' //FAILS } {code} No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files. It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing. The interesting thing is that readFile works. I've even tried using writeFile() to create the file, it made no difference. |
New:
The following Pipeline code produces an error: {code:java} def container = docker.image("any_existing_image_eg_alpine") container.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 archiveArtifacts '/tmp/*.txt' //FAILS } {code} No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files. It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing. The interesting thing is that readFile works. I've even tried using writeFile() to create the file, it made no difference. Update: "fileExists" also fails in a container (returns false when file exists), even though readFile works. |
Description |
Original:
The following Pipeline code produces an error: {code:java} def container = docker.image("any_existing_image_eg_alpine") container.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 archiveArtifacts '/tmp/*.txt' //FAILS } {code} No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files. It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing. The interesting thing is that readFile works. I've even tried using writeFile() to create the file, it made no difference. Update: "fileExists" also fails in a container (returns false when file exists), even though readFile works. |
New:
The following Pipeline code produces an error: {code:java} 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 archiveArtifacts '/tmp/*.txt' //FAILS } {code} No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files. It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing. DSL steps in docker summary (what I've tried): * *readFile()*: works correctly * *writeFile()*: works correctly * *fileExists()*: incorrect (reports false when file exists) * *archiveArtifacts()*: (archives nothing while in inside() ) |
Description |
Original:
The following Pipeline code produces an error: {code:java} 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 archiveArtifacts '/tmp/*.txt' //FAILS } {code} No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files. It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing. DSL steps in docker summary (what I've tried): * *readFile()*: works correctly * *writeFile()*: works correctly * *fileExists()*: incorrect (reports false when file exists) * *archiveArtifacts()*: (archives nothing while in inside() ) |
New:
The following Pipeline code produces an error: {code:java} 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 archiveArtifacts '/tmp/*.txt' //FAILS } {code} No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files. It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing. DSL steps in docker summary (what I've tried): * *readFile()*: works correctly * *writeFile()*: works correctly * *fileExists()*: incorrect (reports false when file exists) * *archiveArtifacts()*: (archives only files under $WORKSPACE tree while in inside() (auto-mounted) ) |
Description |
Original:
The following Pipeline code produces an error: {code:java} 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 archiveArtifacts '/tmp/*.txt' //FAILS } {code} No matter what pattern I've tried with archiveArtifacts, it always reports that it matched no files. It does not appear to be looking on the docker host either, because '/**' or '**' also match nothing. DSL steps in docker summary (what I've tried): * *readFile()*: works correctly * *writeFile()*: works correctly * *fileExists()*: incorrect (reports false when file exists) * *archiveArtifacts()*: (archives only files under $WORKSPACE tree while in inside() (auto-mounted) ) |
New:
The following Pipeline code produces an error: {code:java} 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 archiveArtifacts '/tmp/*.txt' //FAILS } {code} 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. |
Summary | Original: archiveArtifacts not working inside() docker containers | New: archiveArtifacts and fileExists not working inside() docker containers |
Summary | Original: archiveArtifacts and fileExists not working inside() docker containers | New: archiveArtifacts and fileExists inconsistent inside() docker containers |
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.