I have Jenkins master container running in a Kubernetes cluster. I have a separate VM configured as a build slave so that it can build containers.
I am using a Multibranch Pipeline
with the Jenkinsfile in the git repo.
The pipeline builds the Docker image which is a Django app. I have installed django_nose, so it can produce xunit files with the test results.
The Django settings has the following options to enable xunit test results.
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = [
'--with-xunit',
'--xunit-file=/tmp/tests/results/results.xml',
]
In the pipeline, I have the following stage:
stage("Test") {
sh("docker run --rm -i \
-v '${env.WORKSPACE}/tests/results/':/tmp/tests/results \
${image} python3 manage.py test")
junit '${env.WORKSPACE}/tests/results/*.xml'
}
It is mounting a directory in the Jenkins workspace as a volume in the container so that the saved test results can be viewed by Jenkins after the container completes.
When I run the build, I get the following error:
[Pipeline] { (Test)
[Pipeline] sh
[my_project-test-7T6G6Z...QQBYGFA] Running shell script
+ docker run --rm -i -v /home/jenkins/jenkins_home/workspace/my_project-test-7T6G6Z...QQBYGFA/tests/results/:/tmp/tests/results my-registry/username/my_project python3 manage.py test
nosetests --with-xunit --xunit-file=/tmp/tests/results/results.xml --verbosity=1
Creating test database for alias 'default'...
............
----------------------------------------------------------------------
Ran 12 tests in 1.421s
OK
Destroying test database for alias 'default'...
[Pipeline] junit
Recording test results
No test report files were found. Configuration error?
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
I can see that the Django tests are running and passing. If I look on the Jenkins slave VM, I can see that the results.xml file is in the location that it is supposed to be, and it contains the XML results of the tests.
jenkins@jenkins-slave01:~/jenkins_home/workspace$ ls -al /home/jenkins/jenkins_home/workspace/my_project-test-7T6G6Z...QQBYGFA/tests/results/results.xml
-rw-r--r-- 1 root root 1329 Oct 2 09:45 /home/jenkins/jenkins_home/workspace/my_project-test-7T6G6Z...QQBYGFA/tests/results/results.xml
jenkins@jenkins-slave01:~/jenkins_home/workspace$
Why is Jenkins not able to get the test results, since I can see that the file is created?
I figured out the answer. JUnit needs a relative path from within the workspace. You don't need to include the path to the workspace.
junit 'tests/results/*.xml'
I had this error because I had a leading dot in the path to the test results, e.g.:
junit './build/outputs/androidTest-results/connected/flavors/DEV/*.xml'
I'm not sure why, but this fixed it:
junit 'build/outputs/androidTest-results/connected/flavors/DEV/*.xml'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With