Jenkins TestNG plugin does not fetch results from the test-results.xml file - jenkins

In my project workspace, the test-results.xml file exists inside the target\surefire-reports\testng-results.xml directory. But Jenkins fails to read the XML file and gives below error on console.
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: **\target\surefire-reports\testng-results.xml
Did not find any matching files.
To ensure the file isn't too old, I had checked that the test-results.xml (and other files) belong to the latest test run. The Jenkins server is running on Ubuntu 14.04 LTS.
I'm running my tests in this manner: My project root directory has a run_tests.sh script which looks like this:
#!/bin/bash
if [ "$1" = "" ]; then
echo "Please provide a valid suite XML file name."
else
mvn clean
mvn compile
mvn clean test -Dsurefire.suiteXmlFiles="$1"
fi
I just pass the suite XML file name as a parameter to this script in Jenkins (execute shell).
Please help.

I found the solution for this.
Go to Configure of your Job
in General Tab, you may find
Advanced Button, Click on this
Check the check box of "Use custom
workspace", under this you see the Directory text box, here you copy
your Selenium Workspace Folder, for example mine is
"E:\eclipse\eclipse-workspace\WebDriveTest\"
Scroll down the page
under the Post-build Actions, Publish TestNG Results, TestNG XML
report pattern : give like this
"**/target/surefire-reports/testng-results.xml" (check this path in
the same workspace).
I hope this will help you!.

You should be using / instead of \ (since you mentioned that your Jenkins is running on a UNIX box)

Krishnan, in the testng-users Google Group, pointed out that it could be an issue with my Jenkins project workspace, and it was the same.
I changed the default workspace in my Jenkins project.
So I've added the path "$HOME/myWorkspace/myProject/" in my Jenkins project workspace, and "**/target/surefire-reports/testng-results.xml" in my TestNG setting in the same Jenkins project, and it works!
Thank you Krishan for your help.

Please see my answer in another post here, it should be very clear.
In short, it is caused by the current directory was changed to the default Jenkins workspace, you need set your custom workspace in the Job's Config.

I agree with Krishnan Mahadevan usage of '\' instead of '/' while providing the path for TestNG Report also solved my problem.
Extremely important thing to note here:
When providing path for Root POM in the build section '\' is used
C:\Users\harsh\eclipse-workspace\ProjTwo3\pom.xml
When providing path for TestNG XML report pattern in Publish TestNG Result section
'/' is used
C:/Users/harsh/eclipse-workspace/ProjTwo3/target/surefire-reports/testng-results.xml
Console Output:
channel stopped
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern:
C:/Users/harsh/eclipse-workspace/ProjTwo3/target/surefire-reports/testng-results.xml
Saving reports...
Processing 'C:\Users\harsh.jenkins\jobs\MyApplication\builds\12\testng\testng-results.xml'
11.688312% of tests failed, which exceeded threshold of 0%. Marking build as UNSTABLE

Related

Jenkins fails to find SureFire Reports

Jenkins Version : 2.176.2
Executing Selenium tests via Jenkins : Ecplsie+mvn+Jenkins
Selenium Workspace Folder : C:\Users\admin\eclipse-workspace\ACA
The actual location of the testng-results.xml: C:\Users\admin\eclipse-workspace\ACA\target\surefire-reports\testng-results.xml
Jenkins Insatlled / Home Directory: C:\Program Files (x86)\Jenkins
Building in workspace C:\Program Files (x86)\Jenkins\workspace\ACATestAutomationJob
Executing Maven: -B -f C:\Users\admin\eclipse-workspace\ACA\pom.xml clean install
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: **/target/surefire-reports/testng-results.xml
Did not find any matching files.
How do i make jenkins locate this testng-results.xml?
Thanks,
Raj
Look into Jenkins Console Output, it should report where the build is running (so called WORKSPACE) and where TestNG Results Plugin attempts to locate the results file:
The path to the TestNG results file must be relative to the WORKSPACE and have the syntax of Ant FileSet
If you're uncertain regarding how to properly build the path to the test artifacts - post the full paths to WORKSPACE and the testng-results.xml / emailable-report.html and we will help you to come up with the correct definitions.
In the meantime you could use wildcard paths like:
**/testng-results.xml
so Jenkins will scan its WORKSPACE recursively looking for the testng-results.xml file in all available locations
Your install command also looks suspicious, normally you should not be putting your test artifacts to the Maven repository so you might want to use mvn test or mvn verify instead.
More information:
Turbo Boost Your Digital App Test Automation with Jenkins
https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

Jenkins - failed: No test report files were found. Configuration error?

I'm beginner for "Jenkins" and following this tutorial.
At the Sixth step I got below error.
xcodebuild: error: Scheme JenkinsTest is not currently configured for the test action.
Build step 'Xcode' marked build as failure
Recording test results
ERROR: Step ‘Publish JUnit test result report’ failed: No test report files were found. Configuration error?
Finished: FAILURE
In the Test report XMLs I did set "test-reports/.*xml"
I tried to find my solution and also many questions are founded on SO like same issue I have too but did not get solution.
I have some confusion, Is .xml file automatically generated by "Jenkins" or First we manually need to add .xml file ?
In short guide me on right direction based on above error.
You can also enable the 'allowEmptyResults' option so that the junit plugin won't throw an exception when it doesn't find test results.
This way it doesn't matter if the 'test-results' directory exists.
junit allowEmptyResults: true, testResults: '**/test-results/*.xml'
First make sure junit.xml is getting generated after the test run.
Jenkins job at times cannot see past the current workspace. so it is always a good idea to copy the reports back to the current workspace before using it.
cd <path to report>
cp *.xml $WORKSPACE
Now the jenkins should pick-up the report.
Note: The config may show error first(since it cannot find the xml file in workspace) but after a build this should go away and also the result should get recorded
I'm using nosetest (python) to generate an xUnit compatible file and I was getting:
ERROR: No test report files were found. Configuration error?
I was using junit plugin as:
junit "test-results-unit.xml"
junit seems to add WORKSPACE directory by default so using the full PATH to the file wouldn't work either. I created symlink from the resulting file to the WORKSPACE directory to make it work:
sh 'ln -s tests/test-results-unit.xml $WORKSPACE'
junit "test-results-unit.xml"
Other answers suggest copying the files to the workspace directory, but for me simply changing the path to start with '**' seemed to solve the issue
junit '**/test-reports/*.xml'
The Jenkins junit plugin page says that you need to "specify the path to JUnit XML files in the Ant glob syntax". I've not dug into the full details of what this means, but starting the path with '**' was enough to get it working for me.
Thanks #Acid, it really helped me.
First, copy the module/build/test-results to workspace directory
cp -r app/build/test-results $WORKSPACE/test-results
And then I used this wildcard path
**/test-results/**/*.xml
I had the same problem and my test report file name got changed due to an upgrade in scala version,
Hence I have to change from,
junit '/myworkspace/target/myreport.xml'
to
junit '/myworkspace/target/TEST-myreport.xml'
How about:
junit allowEmptyResults: true, testResults: "${WORKSPACE}/test-results/*.xml"
or just:
junit "${WORKSPACE}/test-results/*.xml"
You have to find the path where your test reports are saved in your .jenkins workspace:
/Users/<USERNAME/>/.jenkins/workspace/<PROJECT/>/target/surefire-reports/*.xml
to find the folder type in your terminal:
.jenkins
then
open .

How to check the pmd results in Jenkins?

Have a Java project and just automated it's build process using Jenkins Here is my console output of Jenkin console
18:50:22 Started by user suresh
18:50:22 Building in workspace C:\Program Files (x86)\Jenkins\workspace\pmdtest
18:50:23 [PMD] Collecting PMD analysis files...
18:50:23 [PMD] Finding all files that match the pattern **/pmd.xml
18:50:23 [PMD] Computing warning deltas based on reference build #6
18:50:23 Finished: SUCCESS
I can see that there are messages related to PMD.
May be I need to give something in the below configuration ? above output is when the below box (in image) is empty. Want to PMD all the js files. So tried
However, I do not know how to check the generated report? Is there any location that I have to go and check the results ?
What exactly needs to give there? May be that solves the other problem ?
The Jenkins PMD Plugin doesn't do any analysis, this must be done by the maven pmd plugin. The Jenkins plugin can just display the results.
Try to add the goal pmd:pmd to your maven command, this will generate a result file target/pmd.xml which you need to add to the config (PMD results).

Getting output from remote hudson builds

I have recently added several Hudson agent machines to a working controller.
Some of the builds have result files (Doxygen output, Boost unit test results, cppcheck) which are published using the relevant plugins.
If these builds run on the controller, the output files are published successfully, but if they run on an agent, the build fails because the files cannot be found.
The plugins seem to be looking for the output files on the controller, when of course, they are on the agent.
Is there a way to fix this?
Plugins used:
- Jenkins Cppcheck Plug-in V1.2
- Doxygen Plugin V0.9
- HTML Publisher plugin V0.6
Edit:
Tried archiving suggestion, but I can't get it to work. cppcheck.xml is archived correctly and exists in the relative directory ../lastSuccessful/archive/cppcheck.xml
Hudson log:
Archiving artifacts
[Cppcheck] Starting the cppcheck analysis.
[Cppcheck] No cppcheck test report file(s) were found with the pattern
'../lastSuccessful/archive/cppcheck.xml' relative to
'/home/hudson/.hudson/jobs/1.11-IntegrationDebug/workspace'.
Did you enter a pattern relative to the correct directory?
Did you generate the XML report(s) for Cppcheck?
[Cppcheck] Parsing throws exceptions. No cppcheck test report file(s) were
found with the pattern '../lastSuccessful/archive/cppcheck.xml' relative to
'/home/hudson/.hudson/jobs/1.11-IntegrationDebug/workspace'.
Workaround: copy artifacts into your workspace and publish from there.

Hudson/Jenkins PMD Configuration

I am new to Jenkins and just started configuring it. This is what i have done till now:
Installed and configured Jenkins to display the home page. Added PMD plugin.
Set the HUDSON_HOME to a specific directory > C:\Work\Jenkins
Configured a test build to run a simple do-nothing ant script. It runs successfully
Written an independent pmdbuild.xml to run checks on a set of files in C:\myview (I am using clearcase). This xml also copies the output pmd_results.xml to the workspace directory in $HUDSON_HOME/[job-name]/workspace
Now I added the pmdbuild.xml as a step in my primary build. So my build has 2 steps:
a. Run a simple script, do-nothing.
b. Run pmdbuild.xml which generate pmd_results.xml and place it in $HUDSON_HOME/[job-name]/workspace (HARD-CODED as Jenkins PMD plugin expects the file there)
Jenkins picks up the pmd_results.xml automatically with the plugin and displays warnings and everything.
Now the problem:
If I click on a filename in the PMD results, it gives a filenotfound exception as it is looking for the source file in $HUDSON_HOME/[job-name]/workspace.
My java code files are placed in C:\myview (a clearcase snapshot view)
My question is, do I need all my code files to be present inside $HUDSON_HOME/[job-name]/workspace ?? Meaning can't I tell Jenkins to look for the PMD input files in C:\myview or any other directory instead of $HUDSON_HOME/[job-name]/workspace ??
Sorry for the extremely long description.
Jenkins expects that all the code is in the workspace. Usually Jenkins is used to check out a copy of the code into the workspace, and then runs all build steps on the Sources in the Workspace.
Might seem restraining at first, but it saves you a lot of trouble if you need to move Jenkins to another server, or create a slave instance.
So I would suggest you let Jenkins check out your code (there should be a clearcase plugin) into the workspace, and run the analysis on the checked out code.
If there are compelling reasons why your code has to stay where it is (C:\myview in your case) you can still set the workspace of your build to that directory (find this in the job configuration page, you need to click on the 'extended' button to see the option).

Resources