Running sonarscanner docker image with Azure Pipleine

Hello,
we are using SonarQube 10.0.0.68432.

We have already integrated it successfully to mulitple piplines in our Azure DevOps OnPremise installation and it works perfectly. We got one issue/questions around running the sonarsource/sonar-scanner-cli docker image for one pipeline, where we can not do the analysis locally (due to issues with the required node version for typescript). The issue we are fighting with is branch detection and PR decoration. It seems that we are missing how to pass the data generated by the SonarQubePrepare@5 task to the docker image running the analysis.

What we do:

We run the SonarQubePrepare@5 task and from logs it detects the branch/PR properly.

Next we run the docker image from commandline like this:

 task: PowerShell@2
    displayName: Run SonarQube Scanner
    inputs:
      targetType: inline
      script: |
        docker run `
        --rm `
        --user="$(id -u):$(id -g)" `
        -e SONAR_HOST_URL="<url>" `
        -e SONAR_SCANNER_OPTS="-Dsonar.projectKey=TDWV" `
        -e SONAR_TOKEN="<our token>" `
        -v $(build.SourcesDirectory):/usr/src `
        -v sonar-scanner-cache:/opt/sonar-scanner/.sonar/cache `
        sonarsource/sonar-scanner-cli
    condition: succeeded()

Finally we run:

  - task: SonarQubePublish@5
    inputs:
      pollingTimeoutSec: '300'

The analysis succeeds, but is always sent without branch/PR information to SQ.

What is the proper way to share the results of SonarQubePrepare@5 task to the docker image? Mount another disk? But where is the output of SonarQubePrepare@5 saved to? Or do we need to pass all parameters manually to the image?

Any information we can share further to support the analysis?

Thanks!

Can you expand on this? Take note that you can provide a non-default node installation to the sonar.nodejs.executable analysis parameter as documented here.

If you’re using the docker image, you’ll need to kiss using the SonarQubePrepare@5 analysis step goodbye and pass the required analysis parameters (you can take a look at what environment variables the extension is using here).

And, I would really like to know more about the compatibility issues you’re facing with NodeJS! Maybe we can sort that out so you don’t have to use the Docker image and manually configure anything.

Hi, thanks for your suggestions. We could fix the incompatibility with the node version and can now run the scanner directly. This also fixed our issue. Thanks!

1 Like