jenkinsci / jenkinsci/docker-workflow-plugin
[JENKINS-51462] archiveArtifacts and fileExists inconsistent in docker.inside() closure
- Dominant language
- Java
- Stars
- 527
- Forks
- 422
- Avg merge
- 10m
- Merged PRs (30d)
- 1
Description
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.
---
Originally reported by
akom, imported from: archiveArtifacts and fileExists inconsistent in docker.inside() closure
Raw content of original issue
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.
environment
```
Jenkins 2.112
Docker Pipeline 1.15, 1.17
```
Contributor guide
Assessment
This issue has not been assessed yet.