jenkinsci / jenkinsci/docker-workflow-plugin
[JENKINS-47915] Successful dockerfile job fails intermittently
- Dominant language
- Java
- Stars
- 527
- Forks
- 422
- Avg merge
- 10m
- Merged PRs (30d)
- 1
Description
We are using declarative pipelines and one of the steps uses the Dockerfile agent and mounts the workspace as a volume inside the container and then runs a simple test to make sure a file exists. Frequently the step fails despite it clearly exiting with a 0. This test was originally put in place because later in our pipeline we were getting strange build fails and I needed to verify the volume was correctly mounted by the Dockerfile agent. It is strange it regularly (and randomly) fails despite clearly succeeding.
stage('Dockerfile volume test') {
agent {
dockerfile {
dir 'docker/web_base'
args '-v $WORKSPACE:/var/www'
}
}
steps {
echo 'Testing volume is mounted'
sh '''
if [ -f /var/www/readme.MD ]; then
echo "Volume mounted"
exit 0
else
echo "Error volume not mounted"
exit 1
fi
'''
}
}
Here is some sanitised console output from the relevant stage:
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 1000:1000 -v $WORKSPACE:/var/www -w /var/jenkins_home/workspace/****_feature_****-XQI4C6XJ4O5UMBXPFXK73HT2RDSRQFVROIGJ25NECTJ73F7HNLVQ@2 -v /var/jenkins_home/workspace/****_feature_****-XQI4C6XJ4O5UMBXPFXK73HT2RDSRQFVROIGJ25NECTJ73F7HNLVQ@2:/var/jenkins_home/workspace/****_feature_****-XQI4C6XJ4O5UMBXPFXK73HT2RDSRQFVROIGJ25NECTJ73F7HNLVQ@2:rw,z -v /var/jenkins_home/workspace/****_feature_****-XQI4C6XJ4O5UMBXPFXK73HT2RDSRQFVROIGJ25NECTJ73F7HNLVQ@2@tmp:/var/jenkins_home/workspace/****_feature_****-XQI4C6XJ4O5UMBXPFXK73HT2RDSRQFVROIGJ25NECTJ73F7HNLVQ@2@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat c922be38aabaa3f9b626be62fcd3107c46ab8f7b
[Pipeline] {
[Pipeline] echo
Testing volume is mounted
[Pipeline] sh
[****_feature_****-XQI4C6XJ4O5UMBXPFXK73HT2RDSRQFVROIGJ25NECTJ73F7HNLVQ@2] Running shell script
+ [ -f /var/www/readme.MD ]
+ echo Volume mounted
Volume mounted
+ exit 0
[Pipeline] }
$ docker stop --time=1 3cda9418fb950f1004224a071cde0260b3b387997041380a220230038f5eda0d
$ docker rm -f 3cda9418fb950f1004224a071cde0260b3b387997041380a220230038f5eda0d
It is curious that it reports Jenkins does not appear to be running in a container. We are using sibling containers. I am not sure that is directly relevant to the issue though.
---
Originally reported by scottles, imported from: Successful dockerfile job fails intermittently
Raw content of original issue
We are using declarative pipelines and one of the steps uses the Dockerfile agent and mounts the workspace as a volume inside the container and then runs a simple test to make sure a file exists. Frequently the step fails despite it clearly exiting with a 0. This test was originally put in place because later in our pipeline we were getting strange build fails and I needed to verify the volume was correctly mounted by the Dockerfile agent. It is strange it regularly (and randomly) fails despite clearly succeeding.
stage('Dockerfile volume test') {
agent {
dockerfile {
dir 'docker/web_base'
args '-v $WORKSPACE:/var/www'
}
}
steps {
echo 'Testing volume is mounted'
sh '''
if [ -f /var/www/readme.MD ]; then
echo "Volume mounted"
exit 0
else
echo "Error volume not mounted"
exit 1
fi
'''
}
}Here is some sanitised console output from the relevant stage:
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 1000:1000 -v $WORKSPACE:/var/www -w /var/jenkins_home/workspace/****_feature_****-XQI4C6XJ4O5UMBXPFXK73HT2RDSRQFVROIGJ25NECTJ73F7HNLVQ@2 -v /var/jenkins_home/workspace/****_feature_****-XQI4C6XJ4O5UMBXPFXK73HT2RDSRQFVROIGJ25NECTJ73F7HNLVQ@2:/var/jenkins_home/workspace/****_feature_****-XQI4C6XJ4O5UMBXPFXK73HT2RDSRQFVROIGJ25NECTJ73F7HNLVQ@2:rw,z -v /var/jenkins_home/workspace/****_feature_****-XQI4C6XJ4O5UMBXPFXK73HT2RDSRQFVROIGJ25NECTJ73F7HNLVQ@2@tmp:/var/jenkins_home/workspace/****_feature_****-XQI4C6XJ4O5UMBXPFXK73HT2RDSRQFVROIGJ25NECTJ73F7HNLVQ@2@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat c922be38aabaa3f9b626be62fcd3107c46ab8f7b
[Pipeline] {
[Pipeline] echo
Testing volume is mounted
[Pipeline] sh
[****_feature_****-XQI4C6XJ4O5UMBXPFXK73HT2RDSRQFVROIGJ25NECTJ73F7HNLVQ@2] Running shell script
+ [ -f /var/www/readme.MD ]
+ echo Volume mounted
Volume mounted
+ exit 0
[Pipeline] }
$ docker stop --time=1 3cda9418fb950f1004224a071cde0260b3b387997041380a220230038f5eda0d
$ docker rm -f 3cda9418fb950f1004224a071cde0260b3b387997041380a220230038f5eda0dIt is curious that it reports Jenkins does not appear to be running in a container. We are using sibling containers. I am not sure that is directly relevant to the issue though.
- environment:
Jenkins 2.73.2 docker image (extended to include a few extra required tools installed via apt), running on a Kubernetes cluster using sibling containers.
1 attachment
- [Screenshot from 2017-11-09 12-42-00.png](https://issues.jenkins.io/secure/attachment/40271/Screenshot%20from%202017-11-09%2012-42-00.png)
> 
Contributor guide
Assessment
This issue has not been assessed yet.