Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-70770

waitForQualityGate step fails when with MS sonar scanner

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Critical Critical
    • sonar-plugin
    • None
    • Jenkins 2.387.1
      sonar-plugin 2.15

      We implement a scripted pipeline to perform a sonar analysis on C# repository code.

      Follow a snippet of the pipeline we implemented:

       

      withSonarQubeEnv("Sonar") {
          ...
          sonarProps += [
              "/k:'${sonarProjectKey}'",
              "/n:'${sonarProjectName}'",
              "/v:'${projectVersion}'"
          ]
          run("dotnet '${scannerHome}/SonarScanner.MSBuild.dll' begin ${sonarProps.join(' ')}")
          run("dotnet build ${slnFile}")
          run("dotnet '${scannerHome}/SonarScanner.MSBuild.dll' end /d:sonar.login=${env.SONAR_AUTH_TOKEN}")
          
          def qualityGate = waitForQualityGate(abortPipeline: false, credentialsId: Constants.SONAR_WEBHOOK_SECRET)
          if (qualityGate.status != 'OK') {
              stageResult message: 'Quality Gate not passed', result: 'UNSTABLE'
          }
      }

      When we run a build we get the following log

      + dotnet /home/jenkins/agent/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarQube_MSScanner/SonarScanner.MSBuild.dll begin /d:sonar.host.url=https://sonarqube.xxx /d:sonar.login=****** /d:sonar.userHome=...@tmp/.sonar /d:sonar.pullrequest.branch=feature/test /d:sonar.pullrequest.key=2 /d:sonar.pullrequest.base=master /k:projectNameTest /n:projectNameTest /v:1.0.0
      SonarScanner for MSBuild 5.11
      Using the .NET Core version of the Scanner for MSBuild
      Pre-processing started.
      Preparing working directories...
      21:19:31.606  Updating build integration targets...
      21:19:32.451  Fetching analysis configuration settings...
      21:19:33.423  Provisioning analyzer assemblies for cs...
      21:19:33.424  Installing required Roslyn analyzers...
      21:19:34.296  Provisioning analyzer assemblies for vbnet...
      21:19:34.296  Installing required Roslyn analyzers...
      21:19:34.36  Processing pull request with base branch 'master'.
      21:19:34.495  Downloading from https://sonarqube.dev.opensoftware.it/api/analysis_cache/get?project=projectNameTest&branch=master failed. Http status code is NotFound.
      21:19:34.497  Cache data is not available. Incremental PR analysis is disabled.
      21:19:34.55  Pre-processing succeeded.
      [Pipeline] isUnix
      [Pipeline] sh
      + dotnet build os-backoffice-be.sln
      MSBuild version 17.3.2+561848881 for .NET
        Determining projects to restore...
      ........
      + dotnet /home/jenkins/agent/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarQube_MSScanner/SonarScanner.MSBuild.dll end /d:sonar.login=******
      SonarScanner for MSBuild 5.11
      Using the .NET Core version of the Scanner for MSBuild
      Post-processing started.
      Calling the SonarScanner CLI...
      ........
      The SonarScanner CLI has finished
      21:20:29.781  Post-processing succeeded.
      

      And this is the error we (always) get

      java.lang.IllegalStateException: No previous SonarQube analysis found on this pipeline execution. Please use the 'withSonarQubeEnv' wrapper to run your analysis.
          at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.processStepParameters(WaitForQualityGateStep.java:204)
          at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.start(WaitForQualityGateStep.java:179)
          at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:322)
          at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:196)
          at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:124)
          at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:47)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
          at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
      

      For debug we modify the sources of sonar-plugin and put some log. The expected sonar action is not attached to the build. SonarMarkerAction is the only sonar action type found

      [Pipeline] waitForQualityGate
      hudson.model.CauseAction
      jenkins.metrics.impl.TimeInQueueAction
      jenkins.scm.api.SCMRevisionAction
      org.jenkinsci.plugins.workflow.libs.LibrariesAction
      com.cloudbees.plugins.credentials.builds.CredentialsParameterBinder
      hudson.plugins.git.util.BuildData
      org.jenkinsci.plugins.workflow.steps.scm.MultiSCMRevisionState
      com.cloudbees.jenkins.plugins.bitbucket.FirstCheckoutCompletedInvisibleAction
      org.jenkinsci.plugins.workflow.cps.EnvActionImpl
      hudson.plugins.git.util.BuildData
      **********hudson.plugins.sonar.action.SonarMarkerAction********** com.cloudbees.workflow.rest.endpoints.RunAPI
      org.jenkinsci.plugins.displayurlapi.actions.RunDisplayAction
      org.jenkinsci.plugins.pipeline.modeldefinition.actions.RestartDeclarativePipelineAction
      org.jenkinsci.plugins.workflow.cps.CpsThreadDumpAction
      org.jenkinsci.plugins.workflow.cps.PauseUnpauseAction
      org.jenkinsci.plugins.workflow.cps.replay.ReplayAction
      org.jenkinsci.plugins.workflow.job.views.FlowGraphAction
      org.jenkinsci.plugins.workflow.job.views.FlowGraphTableAction Pipeline Steps
      org.jenkinsci.plugins.workflow.job.views.GraphVizAction
      org.jenkinsci.plugins.workflow.support.actions.WorkspaceRunAction
      

            sonarteam Sonar Team
            nfalco Nikolas Falco
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: