Jenkins JUnit plugin gives error "ERROR: No test report files were found. Configuration error?"
Asked Answered
H

2

6

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?

Hazzard answered 2/10, 2018 at 17:47 Comment(0)
H
12

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'
Hazzard answered 2/10, 2018 at 20:33 Comment(4)
I don't find any solution here?Sanjay
Try making a build from the cli and see if you are able to locate the test results and reports. The paths may be different depending on version and own setup.Boschvark
Hi @zoidberg, do you mean to say instead of junit '${env.WORKSPACE}/tests/results/*.xml' the path should be junit 'tests/results/*.xml'Moratorium
@Deepak, yes, presuming that you have a tests/results directory where the files can be saved.Hazzard
B
2

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'
Bendite answered 16/8, 2019 at 23:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.