The reason I want to disable it is that it adds about an extra 30 seconds to my pipeline when I don't even need it. All I want is for the report to be published to Sonarqube, which is working fine.
My pipeline YAML file:
trigger: none
pool:
name: <REDACTED>
demands:
- agent.name -equals <REDACTED>
stages:
- stage: InstallJava
jobs:
- job:
steps:
- task: CmdLine@2
inputs:
script: |
echo Write your commands here
echo Hello world
pwd
dir
mvn -version
java -version
mvn clean compile
export JAVA_HOME='/usr/lib/jvm/java-11-openjdk-11.0.21.0.9-1.el7_9.x86_64'
- task: MavenAuthenticate@0
inputs:
artifactsFeeds: '<REDACTED>'
- task: SonarQubePrepare@5
inputs:
SonarQube: '<REDACTED> SonarQube'
scannerMode: 'Other'
- task: Maven@4
inputs:
mavenPomFile: 'pom.xml'
goals: 'clean install'
publishJUnitResults: false
javaHomeOption: 'path'
codeCoverageToolOption: 'JaCoCo'
jdkDirectory: '/usr/lib/jvm/java-11-openjdk'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: true
- task: SonarQubePublish@5
inputs:
pollingTimeoutSec: '300'
To answer the question WHY, this unfortunately appears to be by design. The Maven task has the following logic, lifted from the source code of the Maven@4 task.
// Maven task orchestration occurs as follows:
// 1. Check that Maven exists by executing it to retrieve its version.
// 2. Apply any goals for static code analysis tools selected by the user.
// 3. Run Maven. Compilation or test errors will cause this to fail.
// In case the build has failed, the analysis will still succeed but the report will have less data.
// 4. Attempt to collate and upload static code analysis build summaries and artifacts.
// 5. Always publish test results even if tests fail, causing this task to fail.
// 6. If #3 or #4 above failed, exit with an error code to mark the entire step as failed.
Step #5 has some logic to fail the build if the coverage is empty, which appears to be coupled with the implementation of publishing code-coverage artifacts.
I'm assuming that you want both code coverage and unit-test results to be included in the data set published to SonarQube. If they are not needed at all, you can prevent publishing by setting the codeCoverageToolOption
to none
, which will set the isCodeCoverageOpted
variable (shown above) to false.