How can I integrate SonarQube in my Gradle pipeline for Azure DevOps?

My pipeline is running fine with its Gradle task, as follows:

- task: Gradle@2
  displayName: 'Build Android'
  inputs:
    workingDirectory: '$(system.defaultWorkingDirectory)/android'
    gradleWrapperFile: '$(system.defaultWorkingDirectory)/android/gradlew'
    gradleOptions: '-Xmx3072m'
    options: 'clean'
    publishJUnitResults: false
    testResultsFiles: '**/TEST-*.xml'
    tasks: 'assembleRelease'

Now, I’m trying to add SonarQube as shown below.

- task: SonarQubePrepare@4
  inputs:
    SonarQube: SonarQube
    scannerMode: 'Other'
    extraProperties: |
       sonar.projectKey=$(SONAR_PREFIX_KEY)-$(app-name):$(app-name)
       sonar.projectName=$(SONAR_PREFIX_KEY)-$(app-name):$(app-name)
       sonar.branch.name=$(Build.SourceBranchName)
       sonar.host.url=$(SONAR_HOST)
       sonar.login=$(SONAR_TOKEN)

- task: Gradle@2
        displayName: 'Build Android'
        inputs:
          gradleWrapperFile: '$(system.defaultWorkingDirectory)/android/gradlew'
          workingDirectory: '$(system.defaultWorkingDirectory)/android'
          options: 'clean'
          tasks: 'assembleRelease'
          publishJUnitResults: false
          javaHomeOption: 'JDKVersion'
          gradleOptions: '-Xmx3072m'
          sonarQubeRunAnalysis: true
          sqGradlePluginVersionChoice: 'specify'
          sonarQubeGradlePluginVersion: '2.6.1'
          checkStyleRunAnalysis: true
          findBugsRunAnalysis: false
          pmdRunAnalysis: true
          spotBugsAnalysis: false

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

When running the pipeline, I’m getting the following error.

Execution failed for task ':react-native-auth0:processDebugAndroidTestManifest'.
Error: The process '/Users/runner/work/1/s/android/gradlew' failed with exit code 1
    at ExecState._setResult (/Users/runner/work/_tasks/Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4/2.191.0/node_modules/azure-pipelines-task-lib/toolrunner.js:944:25)
    at ExecState.CheckComplete (/Users/runner/work/_tasks/Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4/2.191.0/node_modules/azure-pipelines-task-lib/toolrunner.js:927:18)
    at ChildProcess.<anonymous> (/Users/runner/work/_tasks/Gradle_8d8eebd8-2b94-4c97-85af-839254cc6da4/2.191.0/node_modules/azure-pipelines-task-lib/toolrunner.js:840:19)
    at ChildProcess.emit (events.js:198:13)
    at maybeClose (internal/child_process.js:982:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)

Hi,

Welcome to the community!

This looks unrelated to analysis. Unless maybe there’s some sort of syntax error in the SonarQube task? I don’t know enough about Gradle to spot anything, but…

 
Ann

Hi @ganncamp thanks for your response. The build pipeline is running good without SonarQube tasks, but when I add the SonarQube tasks it fails with that error.

Hi, Have you found a solution to your problem? I have the same problem. I have been trying many things to solve the same problem but so far with no success. If you had found a solution, sharing that would be most welcomed.
Best regards,

Any luck with getting it to work. I am facing the same issue and I am trying to use SonarCloud

Hi @Baso1st,

Welcome to the community!

Can you provide a full log?

 
Ann

Hi I could make it work on my CI pipeline:

 - task: SonarQubePrepare@4
      displayName: Prepare SonarQube
      condition: and(succeeded(),eq(variables.ableToScan, 'true'))
      inputs:
        SonarQube: 'SonarQube'
        scannerMode: 'CLI'
        configMode: 'file'
        extraProperties: |
          sonar.projectKey=$(SONAR_PREFIX_KEY)-$(app-name):$(app-name)
          sonar.projectName=$(SONAR_PREFIX_KEY)-$(app-name):$(app-name)
          sonar.branch.name=$(SonarBranchName)
          sonar.host.url=$(SONAR_HOST)
          sonar.login=$(SONAR_TOKEN)

    - task: SonarQubeAnalyze@5
      condition: and(succeeded(),eq(variables.ableToScan, 'true'))
      displayName: Run SonarQube analysis

    - task: SonarQubePublish@5
      displayName: 'Publish SonarQube analysis'
      condition: and(succeeded(),eq(variables.ableToScan, 'true'))
      inputs:
        pollingTimeoutSec: '300'

    - task: sonar-buildbreaker@8
      condition: and(succeeded(),eq(variables.ableToScan, 'true'))
      displayName: "Evaluate SonarQube results"
      inputs:
        SonarQube: 'SonarQube'     

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