SonarCloudAnalyze@2 task fails in Azure DevOps pipeline with "Failed to extract archive"

SonarCloudAnalyze@2 task fails in Azure DevOps pipeline with “Failed to extract archive” -message. Pipelines are running in self hosted agent. The file to which the error points to, exists but with zero size. Tried deleting whole .sonar -directory but the issue persists.

Output of pipeline

10:47:30.109 INFO  Scanner configuration file: /home/azagent/azagent-2/_work/_temp/115190c7-7448-40c5-939a-6c612de7f8cd/sonar-scanner-6.0.0.4432/conf/sonar-scanner.properties
10:47:30.115 INFO  Project root configuration file: NONE
10:47:30.141 INFO  SonarScanner CLI 6.0.0.4432
10:47:30.143 INFO  Java 17.0.11 Red Hat, Inc. (64-bit)
10:47:30.144 INFO  Linux 5.14.0-427.16.1.el9_4.x86_64 amd64
10:47:30.176 INFO  User cache: /home/azagent/.sonar/cache
10:47:30.625 INFO  JRE provisioning: os[linux], arch[x86_64]
10:47:31.808 INFO  EXECUTION FAILURE
10:47:31.809 INFO  Total time: 1.741s
##[error]10:47:31.809 ERROR Error during SonarScanner CLI execution
java.lang.IllegalStateException: Failed to extract archive
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.extractArchive(JavaRunnerFactory.java:200)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.getJreFromServer(JavaRunnerFactory.java:145)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.createRunner(JavaRunnerFactory.java:85)
	at org.sonarsource.scanner.lib.internal.ScannerEngineLauncherFactory.createLauncher(ScannerEngineLauncherFactory.java:53)
	at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(ScannerEngineBootstrapper.java:117)
	at org.sonarsource.scanner.cli.Main.analyze(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:63)
Caused by: java.nio.file.NoSuchFileException: /home/azagent/.sonar/cache/bcb1b7b8ad68c93093f09b591b7cb17161d39891f7d29d33a586f5a328603707/jre1162657528265033278/jdk-17.0.11+9-jre/lib/server/classes.jsa
	at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
	at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:218)
	at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:484)
	at java.base/java.nio.file.Files.newOutputStream(Files.java:228)
	at java.base/java.nio.file.Files.copy(Files.java:3160)
	at org.sonarsource.scanner.lib.internal.util.CompressionUtils.extractTarGz(CompressionUtils.java:142)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.extract(JavaRunnerFactory.java:234)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.extractArchive(JavaRunnerFactory.java:193)
	... 6 common frames omitted

Hey there.

Is the error always on this file, classes.jsa, on successive runs?

Hi Colin,

Yeah it’s always the same file.

Thanks. I’m not sure what to recommend here, so I’ve flagged it for some expert attention. You can revert to using v1 of the tasks for now, which should unblock you.

Hi Colin,

Thanks for the suggestion, I’ve changed tasks back to version 1 and builds seem to work alright now. As an additional information; version 2 tasks did work for some time but started failing quite recently. If that helps finding the issue. When are version 1 tasks deprecating?

It will be a while (months, not weeks). I don’t have a date to share, and we’ll announce it beforehand.

There seems to be something causing the JRE provided by sonarcloud to not download correctly based on the fact that

exists but with zero size

This usually means something is interfering with the download for the requested file. I believe the request below is what is failing for you.

https://scanner.sonarcloud.io/jres/OpenJDK17U-jre_x64_linux_hotspot_17.0.11_9.tar.gz

In order to get more information, you can pass the sonar.verbose=true in the sonar-project.properties file or in the pipeline step

  - task: SonarCloudPrepare@2
    inputs:
      SonarCloud: 'SonarCloud'
      organization: '***'
      scannerMode: 'CLI'
      configMode: 'file'
      extraProperties: |
        sonar.verbose=true

and you will get more info about the failed request.

Hi Lucas,

Is it possible that one single file inside archive is corrupted because of the interference during download? Anyways I set sonar.verbose to true as suggested and tried running with v2 again, and this time everything seems to work like a charm. Interesting fact that I checked all build servers, and that classes.jsa file exists with zero size in all of them but everything is still working. Was something fixed at your end?

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube 10.6, ADO Task 6.2 )
  • how is SonarQube deployed: zip
2024-07-02T21:23:28.2734908Z ##[section]Starting: Run Code Analysis
2024-07-02T21:23:28.2747262Z ==============================================================================
2024-07-02T21:23:28.2747448Z Task         : Run Code Analysis
2024-07-02T21:23:28.2747552Z Description  : Run scanner and upload the results to the SonarQube server.
2024-07-02T21:23:28.2747699Z Version      : 6.2.0
2024-07-02T21:23:28.2747783Z Author       : sonarsource
2024-07-02T21:23:28.2747888Z Help         : This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarqube-extension-for-azure-devops/)
2024-07-02T21:23:28.2748204Z ==============================================================================
2024-07-02T21:23:31.1781216Z [command]C:\Windows\system32\cmd.exe /D /S /C "D:\A\1\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\6.2.0\sonar-scanner\bin\sonar-scanner.bat"
2024-07-02T21:23:32.5418902Z 17:23:32.527 INFO  Scanner configuration file: D:\A\1\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\6.2.0\sonar-scanner\bin\..\conf\sonar-scanner.properties
2024-07-02T21:23:32.5449156Z 17:23:32.543 INFO  Project root configuration file: NONE
2024-07-02T21:23:32.5818815Z 17:23:32.576 INFO  SonarScanner CLI 6.1.0.4477
2024-07-02T21:23:32.5864930Z 17:23:32.576 INFO  Java 17.0.11 Eclipse Adoptium (64-bit)
2024-07-02T21:23:32.5874023Z 17:23:32.576 INFO  Windows Server 2019 10.0 amd64
2024-07-02T21:23:32.6155754Z 17:23:32.609 INFO  User cache: C:\Users\***\.sonar\cache
2024-07-02T21:23:33.4037555Z 17:23:33.401 INFO  JRE provisioning: os[windows], arch[amd64]
2024-07-02T21:23:33.7944027Z 17:23:33.785 INFO  EXECUTION FAILURE
2024-07-02T21:23:33.7957230Z 17:23:33.785 INFO  Total time: 1.324s
2024-07-02T21:23:33.8024499Z ##[error]17:23:33.785 ERROR Error during SonarScanner CLI execution
java.lang.IllegalStateException: Failed to extract archive
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.extractArchive(JavaRunnerFactory.java:200)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.getJreFromServer(JavaRunnerFactory.java:145)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.createRunner(JavaRunnerFactory.java:85)
	at org.sonarsource.scanner.lib.internal.ScannerEngineLauncherFactory.createLauncher(ScannerEngineLauncherFactory.java:53)
	at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(ScannerEngineBootstrapper.java:118)
	at org.sonarsource.scanner.cli.Main.analyze(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:63)
Caused by: java.nio.file.NoSuchFileException: C:\Users\***\.sonar\cache\4bafe2e94439c8193fc8c68247cb0dbaf4e80265b903288f63f128304f129bbe\jre6713448976210662761\jdk-17.0.11+9-jre\bin\server\classes.jsa
	at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
	at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:236)
	at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:484)
	at java.base/java.nio.file.Files.newOutputStream(Files.java:228)
	at org.sonarsource.scanner.lib.internal.util.CompressionUtils.copy(CompressionUtils.java:120)
	at org.sonarsource.scanner.lib.internal.util.CompressionUtils.unzip(CompressionUtils.java:95)
	at org.sonarsource.scanner.lib.internal.util.CompressionUtils.unzip(CompressionUtils.java:67)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.extract(JavaRunnerFactory.java:231)
	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.extractArchive(JavaRunnerFactory.java:193)
	... 6 common frames omitted
2024-07-02T21:23:33.8036443Z 17:23:33.785 ERROR Error during SonarScanner CLI execution
2024-07-02T21:23:33.8036721Z java.lang.IllegalStateException: Failed to extract archive
2024-07-02T21:23:33.8038931Z 	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.extractArchive(JavaRunnerFactory.java:200)
2024-07-02T21:23:33.8039298Z 	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.getJreFromServer(JavaRunnerFactory.java:145)
2024-07-02T21:23:33.8039646Z 	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.createRunner(JavaRunnerFactory.java:85)
2024-07-02T21:23:33.8039999Z 	at org.sonarsource.scanner.lib.internal.ScannerEngineLauncherFactory.createLauncher(ScannerEngineLauncherFactory.java:53)
2024-07-02T21:23:33.8040350Z 	at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(ScannerEngineBootstrapper.java:118)
2024-07-02T21:23:33.8040653Z 	at org.sonarsource.scanner.cli.Main.analyze(Main.java:75)
2024-07-02T21:23:33.8040897Z 	at org.sonarsource.scanner.cli.Main.main(Main.java:63)
2024-07-02T21:23:33.8041297Z Caused by: java.nio.file.NoSuchFileException: C:\Users\***\.sonar\cache\4bafe2e94439c8193fc8c68247cb0dbaf4e80265b903288f63f128304f129bbe\jre6713448976210662761\jdk-17.0.11+9-jre\bin\server\classes.jsa
2024-07-02T21:23:33.8041690Z 	at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
2024-07-02T21:23:33.8041998Z 	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
2024-07-02T21:23:33.8042307Z 	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
2024-07-02T21:23:33.8042619Z 	at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:236)
2024-07-02T21:23:33.8042937Z 	at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:484)
2024-07-02T21:23:33.8043220Z 	at java.base/java.nio.file.Files.newOutputStream(Files.java:228)
2024-07-02T21:23:33.8043502Z 	at org.sonarsource.scanner.lib.internal.util.CompressionUtils.copy(CompressionUtils.java:120)
2024-07-02T21:23:33.8043815Z 	at org.sonarsource.scanner.lib.internal.util.CompressionUtils.unzip(CompressionUtils.java:95)
2024-07-02T21:23:33.8044128Z 	at org.sonarsource.scanner.lib.internal.util.CompressionUtils.unzip(CompressionUtils.java:67)
2024-07-02T21:23:33.8044443Z 	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.extract(JavaRunnerFactory.java:231)
2024-07-02T21:23:33.8044771Z 	at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.extractArchive(JavaRunnerFactory.java:193)
2024-07-02T21:23:33.8045015Z 	... 6 common frames omitted
2024-07-02T21:23:33.8045794Z ##[error]17:23:33.785 ERROR 
17:23:33.785 ERROR Re-run SonarScanner CLI using the -X switch to enable full debug logging.
2024-07-02T21:23:33.8046352Z 17:23:33.785 ERROR 
2024-07-02T21:23:33.8046580Z 17:23:33.785 ERROR Re-run SonarScanner CLI using the -X switch to enable full debug logging.
2024-07-02T21:23:33.9511759Z ##[warning]Can't find loc string for key: LIB_ProcessExitCode
2024-07-02T21:23:33.9517999Z ##[warning]Error while executing SonarQube:Analyze task: LIB_ProcessExitCode D:\A\1\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\6.2.0\sonar-scanner\bin\sonar-scanner.bat 1
2024-07-02T21:23:33.9520007Z ##[error]LIB_ProcessExitCode D:\A\1\_work\_tasks\SonarQubeAnalyze_6d01813a-9589-4b15-8491-8164aeb38055\6.2.0\sonar-scanner\bin\sonar-scanner.bat 1
2024-07-02T21:23:33.9728799Z ##[section]Finishing: Run Code Analysis

Hi @skabra,

In our case we are using Sonar Cloud, not Sonar Qube. We had this issue with SonarCloudAnalyze@2 -task, but like I mentioned yesterday, everything seems to work again. The issue though was exactly the same as in your code snippet.

Starting: Run SonarCloud analysis
==============================================================================
Task         : Run Code Analysis
Description  : Run scanner and upload the results to the SonarCloud server.
Version      : 2.2.0
Author       : sonarsource
Help         : This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarcloud-extension-for-azure-devops/)
==============================================================================

Given that @Janne_Rantala was able to resolve the issue with a second run, I recommend clearing the cache directory and re-run the analysis.

Clearing out the cache directory on the ADO build agent did not help.