Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 897
zoidberg Avatar asked Dec 13 '22 14:12

zoidberg


2 Answers

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'
like image 178
zoidberg Avatar answered Dec 28 '22 10:12

zoidberg


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'
like image 27
Big McLargeHuge Avatar answered Dec 28 '22 09:12

Big McLargeHuge