6

The question may sound silly, but I haven't found how to configure the XML report path in the Post-build Junit task after an hour of manipulations. I generate the JUnit test report (the XML file) here :

C:\Program Files\Jenkins\jobs\UPWSP\workspace\up\UPWSP\current\06-Java Unit Testing\junit\TESTS-TestSuites.xml

And the job using the XML has its worskpace at this path :

C:\Program Files\Jenkins\jobs\UPWSP - Tests JUnit\workspace\

The JUnit report post-build task seems to take only relatives path and I already tried with

../../UPWSP/up/UPWSP/current/06-Java Unit Testing/junit/TESTS-TestSuites.xml

**../../UPWSP/up/UPWSP/current/06-Java Unit Testing/junit/TESTS-TestSuites.xml

It always tells me '..' is not a valid path, and an absolute path won't work either. Any idea of how I should use it?

6 Answers 6

14

AFAIK, the path for the JUnit XML file has to be a sub-directory of your project. It should not be outside the job's workspace. Once you have created a directory inside workspace, say for example, junit-test, then the following should work as expected when specified in Test report XMLs section: junit-test\TESTS-TestSuites.xml

1
  • 1
    Jenkins can reach anywhere under $WORKSPACE - a sub-directory is not required. Jun 8, 2017 at 20:38
6

You can use wildcards like **/target/surefire-reports/*.xml or, in your case, **/junit/*.xml

0
3

This is a work around and not an actual answer. I had to copy the xml to the job directory with a xcopy command line. My job is now working, but that's not how I expected things to work

1

Try putting this in the "Test report XMLs" field (assuming you are on windows machine):

up\UPWSP\current\06-Java Unit Testing\junit\*.xml

I am not clear about "job using the XML" part you detailed. How is that related to the job generating the junit reports?

1
  • The reports generate a xml file, and I use it in the same job :)
    – nivolas
    Sep 12, 2014 at 13:07
1

You have to put junit step into dir step like this:

pipeline{
  stages{
    stage("Run tests")
      steps{
        echo "Here generate some test_result.xml files in /some/path"
      }
  }
  post {
    success {
      dir('/some/path')
      {
        junit '**/test_result.xml'
      }
    }
}

}

2
  • I don't know what version this was tested with, but for me it doesn't work.
    – xtofl
    Jul 16, 2020 at 13:44
  • 2.332.2 - it works. Helped me with the case when k8s agent steps were used inside common bare-metal agent steps. env.WORKSPACE inside k8s agent steps was pointing to workspace of bare-metal agent for some reason..
    – sintasy
    Jul 21, 2022 at 13:13
0

On windows, use explorer and go to your installation directory. Something like this C:\Users\me\.jenkins\workspace\PetClinic\target. Add a new folder. Go back to Jenkins dashboard. If you see a red x in post-build actions, click it. Reselect the options and add the new path **/target/newfolder/*.xml. edit: Find the folder that has the tests in it from the cloned repo. Use that folder, in my case it is surefire-reports

1
  • That ship has sailed! I don't have the environment to test things anymore. This questions is from 2014 :)
    – nivolas
    Mar 6, 2020 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.