Genric Report from cypress testing fails upload

SonarQube 9.7.0.61563
Sonar dotnet scanner: latest

Having a lot of trouble troubleshooting why my test results are not being uploaded and are being rejected by the scanner. Error is:

INFO: Parsing /builds/rocket/boost/src/TestResults/cypress/sonar-generic.xml
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:18.027s
INFO: Final Memory: 19M/70M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: Error during parsing of generic test execution report '/builds/rocket/boost/src/TestResults/cypress/sonar-generic.xml'. Look at the SonarQube documentation to know the expected XML format.
ERROR: Caused by: /builds/rocket/boost/src/TestResults/cypress/sonar-generic.xml (No such file or directory)
ERROR: 
The SonarScanner did not complete successfully

Here is how I am referring the file:

    - apt-get install --yes openjdk-11-jre
    - dotnet tool install --global dotnet-sonarscanner
    - dotnet sonarscanner begin /k:"$SONAR_PROJECT" /d:sonar.login="$SONAR_TOKEN" /d:sonar.host.url="$SONAR_HOST_URL"
      /d:sonar.sources="src"
      /d:sonar.exclusions="$SONAR_CODE_EXCLUSIONS"
      /d:sonar.tests="src"
      /d:sonar.test.inclusions="$SONAR_TEST_INCLUSIONS"
      /d:sonar.cs.vstest.reportsPaths="${CI_PROJECT_DIR}/src/TestResults/csharp/*.trx"
      /d:sonar.testExecutionReportPaths="${CI_PROJECT_DIR}/src/TestResults/react/sonar-generic.xml,${CI_PROJECT_DIR}/src/TestResults/cypress/sonar-generic.xml"
      /d:sonar.coverage.exclusions="$SONAR_COVERAGE_EXCLUSIONS"
      /d:sonar.coverageReportPaths="${CI_PROJECT_DIR}/src/TestResults/SonarQube.xml"
    - dotnet build --configuration:$BUILD_CONFIGURATION src/$SOLUTIONNAME
    # No need to run tests here, just include the test and coverage reports created from all previous jobs
    - dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"

The file /builds/rocket/boost/src/TestResults/cypress/sonar-generic.xml definitely exists at that point in the build.

The file I am trying to upload looks like this (UTF-8, LF)

<?xml version="1.0" encoding="utf-8"?>
<testExecutions version="1">
  <file path="/builds/rocket/boost/src/WebsiteHost.UITests/cypress/e2e/bookings.cy.ts">
    <testCase name="Given a registered car - when create a booking, then booking added" duration="14127"></testCase>
  </file>
  <file path="/builds/rocket/boost/src/WebsiteHost.UITests/cypress/e2e/cars.cy.ts">
    <testCase name="Given no cars - when create new car, then unregistered car added" duration="6736"></testCase>
  </file>
  <file path="/builds/rocket/boost/src/WebsiteHost.UITests/cypress/e2e/login.cy.ts">
    <testCase name="Given an unauthenticated user - when access homepage, then loads login page" duration="1734"></testCase>
    <testCase name="Given a unverified user - when login, then shows error" duration="3964"></testCase>
    <testCase name="Given an authenticated user - when login successful, then goes to home page" duration="4268"></testCase>
    <testCase name="Given an authenticated user - when logout, then goes back to login page" duration="4059"></testCase>
  </file>
  <file path="/builds/rocket/boost/src/WebsiteHost.UITests/cypress/e2e/password.cy.ts">
    <testCase name="Given a unverified user - when forgot password, and not verified then error" duration="2988"></testCase>
    <testCase name="Given a registered user - when forgot password, reset password and login with new password, then can access homepage" duration="8716"></testCase>
    <testCase name="Given a registered user - when forgot password, and token expired then resend" duration="2362"></testCase>
    <testCase name="Given a registered user - when forgot password, and token used then success" duration="1976"></testCase>
  </file>
  <file path="/builds/rocket/boost/src/WebsiteHost.UITests/cypress/e2e/registration.cy.ts">
    <testCase name="Given an unauthenticated user - when on-boarded, then can access homepage" duration="9227"></testCase>
  </file>
</testExecutions>

This file is produced by the npm package cypress-sonarqube-reporter

What I have tried?

lots of things, oh boy!

However, the only real clue I have is that: if I run the exact same scanner commands and build on my local Windows 11 machine, the same file is produced (albeit with different paths), and it uploads without error.

When run on our gitlab CI server (which is a linux docker container) it fails. As described above.
Apart from the differences in paths, the files are identical. AFAICT

Please help me resolve? this is super frustrating.

Hi,

Can you turn on debug analysis logging and post the logs? (Add -Dsonar.log.level=DEBUG on the analysis command line.)

 
Ann

Thanks for helping me out with these problems @ganncamp, so soon after the Christmas break,

I have added: /d:sonar.log.level=DEBUG to my command.

Here is what it says:

20:23:51.916 INFO: Parsing /builds/rocket/boost/src/TestResults/cypress/sonar-generic.xml
20:23:51.939 DEBUG: eslint-bridge server will shutdown
20:23:56.941 DEBUG: eslint-bridge server closed
20:23:58.392 INFO: ------------------------------------------------------------------------
20:23:58.394 INFO: EXECUTION FAILURE
20:23:58.395 INFO: ------------------------------------------------------------------------
20:23:58.396 INFO: Total time: 1:29.038s
20:23:58.541 INFO: Final Memory: 19M/70M
20:23:58.541 INFO: ------------------------------------------------------------------------
20:23:58.541 ERROR: Error during SonarScanner execution
Error during parsing of generic test execution report '/builds/rocket/boost/src/TestResults/cypress/sonar-generic.xml'. Look at the SonarQube documentation to know the expected XML format.
Caused by: java.io.FileNotFoundException: /builds/rocket/boost/src/TestResults/cypress/sonar-generic.xml (No such file or directory)
	at java.base/java.io.FileInputStream.open0(Native Method)
	at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
	at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
	at org.sonar.scanner.genericcoverage.GenericTestExecutionReportParser.parse(GenericTestExecutionReportParser.java:75)
	at org.sonar.scanner.genericcoverage.GenericTestExecutionSensor.execute(GenericTestExecutionSensor.java:87)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:64)
	at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:399)
	at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:395)
	at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:364)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:135)
	at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
	at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Process returned exit code 2
The SonarScanner did not complete successfully
20:23:58.895  Post-processing failed. Exit code: 1
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

The XML I gave in the previous post is in the file /builds/rocket/boost/src/TestResults/cypress/sonar-generic.xml which was passed from a previous build step (in gitlab), and is present in the gitlab step that this scanner command is running.

1 Like

OK, I found a problem with the gitlab artifacts not working properly providing the cypress results.
Had nothing to do with sonar really. That fixed this one.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.