Azure DevOps CLI scanner JRE provisioning

Hello,

We’re using the Azure DevOps pipelines plugin for SonarCloud with self-hosted runners that do not have a JRE.

For .NET projects, we’ve been using the JRE provisioning capability of the 7+ .NET scanner (by specifying msBuildVersion to 7+ when the AZDO plugin was at version 2, and now by leaving the defaults since version 3 following the recent announcement).

Example task for .NET:

- task: SonarCloudPrepare@3
  inputs:
    SonarCloud: '...'
    organization: '...'
    scannerMode: 'dotnet'
    projectKey: '...'
    projectName: '...'

For JavaScript projects, we want to use the same JRE provisioning capability of the 6+ CLI scanner, but we’re encountering an issue. Given the following definition:

- task: SonarCloudPrepare@3
  inputs:
    SonarCloud: '...'
    organization: '...'
    scannerMode: 'cli'
    configMode: 'file'

We have a JRE provisioning error:

ERROR: JAVA_HOME not found in your environment, and no Java
       executable present in the PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation, or add "java.exe" to the PATH

We’ve tracked the problem down to the runner downloading the “Any” platform variant of the CLI scanner, which does not support JRE provisioning, and as a workaround we’re abusing the cliScannerVersion property to force the download of the platform-specific variant:

- task: SonarCloudPrepare@3
  inputs:
    SonarCloud: '...'
    organization: '...'
    scannerMode: 'cli'
    cliScannerVersion: '6.2.1.4610-windows-x64'
    configMode: 'file'

This workaround resolves the issue, but this feels “hacky” and we now have to regularly update the pipeline definition to follow new releases.

Maybe having a separate property available in the AZDO plugin to specify the platform while keeping the default version would be good enough for us and doesn’t seem like a breaking change.

A few examples of how it might work:

- task: SonarCloudPrepare@3
  inputs:
    scannerMode: 'cli'
    # ...
# => Downloads "sonar-scanner-cli-[default version].zip"

- task: SonarCloudPrepare@3
  inputs:
    scannerMode: 'cli'
    cliScannerVersion: '6.2.1.4610'
    # ...
# => Downloads "sonar-scanner-cli-6.2.1.4610.zip"

- task: SonarCloudPrepare@3
  inputs:
    scannerMode: 'cli'
    cliScannerPlatform: 'windows-x64'
    # ...
# => Downloads "sonar-scanner-cli-[default version]-windows-x64.zip"

- task: SonarCloudPrepare@3
  inputs:
    scannerMode: 'cli'
    cliScannerVersion: '6.2.1.4610'
    cliScannerPlatform: 'windows-x64'
    # ...
# => Downloads "sonar-scanner-cli-6.2.1.4610-windows-x64.zip"
2 Likes

Hi @cfebl

Thanks for your suggestion, this is a fair point.

I have created a ticket in the backlog: Jira

Hello, thanks, that’s great news!