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

Sonar scanner plugin fail in declarative pipeline on kubernetes agent

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • sonar-plugin
    • None
    • Jenkins 2.414.3, SonarQube Scanner 2.17, declarative pipeline, multi container kubernetes agent

      After update to SonarQube Scanner from version 2.16.1 to 2.17 the SonarQube Scanner breaks the pipeline when the declarative pipeline stage ends. The SonarQube Scanner 2.16.1 works with the same configuration well.

      We use Jenkins master with the kubernetes plugins and our agents contains multiple containers. Our default container is an other container than the container where the SonarQube scan is done (maven-jdk11).

      We use the SonarQube maven plugin within the following stage

      stages{
          stage('Build and Deploy') {
              steps {
                  buildAndDeploy()
                  container('maven-jdk11') {
                      sonar()
                  }
              }
              post {
                  unstable {
                      error('Deployment is aborted due to test failure(s)!')
                  }
              }
          }
      }
      
      void sonar() {
          withSonarQubeEnv('SonarQube') {
               sh('mvn sonar:sonar')
          }
      } 
      

      The SonarQube scan is successful and also the report is uploaded successfully to the SonarQube server.

      We can see following logs

      [INFO] Analysis report generated in 109ms, dir size=336.3 kB
      [INFO] Analysis report compressed in 39ms, zip size=89.2 kB
      [INFO] Analysis report uploaded in 51ms
      [INFO] ANALYSIS SUCCESSFUL, you can find the results at: https://sonarqube.company.com/dashboard?id=projectid%3Aproject&branch=main
      [INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
      [INFO] More about the report processing at https://sonarqube.company.com/api/ce/task?id=AYzgu4GrazA0Y79AmlPr
      [INFO] Executing post-job 'Final report'
      [INFO] Turn debug info on to get more details (sonar-scanner -X -Dsonar.verbose=true ...).
      [INFO] Analysis total time: 13.496 s
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD SUCCESS
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time:  21.427 s
      [INFO] Finished at: 2024-01-06T21:43:54Z
      [INFO] ------------------------------------------------------------------------
      [Pipeline] }
      [Pipeline] // withSonarQubeEnv
      [Pipeline] }
      [Pipeline] // container
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      Failed in branch Deploy
      [Pipeline] // parallel
      Post stage
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // container
      [Pipeline] }
      [Pipeline] // withEnv
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] }
      [Pipeline] // podTemplate
      [Pipeline] End of Pipeline
      Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: a0e21456-4874-494f-ada8-e25ff97bed54
      /home/jenkins/agent/workspace/project_repo does not exist.
      	at org.apache.tools.ant.types.AbstractFileSet.getDirectoryScanner(AbstractFileSet.java:512)
      	at hudson.plugins.sonar.utils.SonarUtils.find(SonarUtils.java:130)
      	at hudson.plugins.sonar.utils.SonarUtils.extractReportTask(SonarUtils.java:102)
      	at hudson.plugins.sonar.utils.SonarUtils.addBuildInfoTo(SonarUtils.java:160)
      	at hudson.plugins.sonar.SonarBuildWrapper$AddBuildInfo.tearDown(SonarBuildWrapper.java:217)
      	at org.jenkinsci.plugins.workflow.steps.CoreWrapperStep$Callback.finished(CoreWrapperStep.java:207)
      	at org.jenkinsci.plugins.workflow.steps.CoreWrapperStep$Execution2$Callback2.finished(CoreWrapperStep.java:150)
      	at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution$TailCall.lambda$onSuccess$0(GeneralNonBlockingStepExecution.java:140)
      	at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution.lambda$run$0(GeneralNonBlockingStepExecution.java:77)
      	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      	at java.base/java.lang.Thread.run(Thread.java:829)
      [Bitbucket] Notifying commit build result
      [Bitbucket] Build result notified
      Finished: FAILURE

            sonarteam Sonar Team
            mi_ko Milan Konzal
            Votes:
            16 Vote for this issue
            Watchers:
            19 Start watching this issue

              Created:
              Updated:
              Resolved: