2

Does SonarQube scanner support BlueOcean pipeline plugin without maven and docker, if it does how does the script works in Jenkinsfile?

I'm new to Jenkins and BlueOcean and have tried all the basic possible aspects available.

If the SonarQube plugin did support Declarative:

pipeline {
  agent any
  stages {
    stage('SonarQube analysis') {
      tools {
        sonarQube 'SonarQube Scanner 2.8'
      }
      steps {
        withSonarQubeEnv('SonarQube Scanner') {
          sh 'sonar-scanner'
        }
      }
    }
  }
}
agabrys
  • 8,728
  • 3
  • 35
  • 73
Ali Khawar
  • 41
  • 1
  • 1
  • 5

2 Answers2

4

We cannot say that the SonarQube scanner supports or does not support BlueOcean. BlueOcean is a presentation layer which displays data provided by stages (example: logs).

SonarQube scanner generates logs, so BlueOcean can displays it. I do not think that this type of relationship can be classified as a "support of".


EDIT:

You can execute an analysis in Declarative Pipeline by using the following code:

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                def scannerHome = tool 'SonarQubeScanner3'
                withSonarQubeEnv('SonarQube') {
                    sh "${scannerHome}/bin/sonar-scanner"
                }
            }
        }
    }
}

You have also add a SonarQube server in Manage Jenkins → Configure System → SonarQube servers:

SonarQube servers

and SonarQube scanner in Manage Jenkins → Global Tool Configuration → SonarQube Scanner:

SonarQube scanner

The name of the:

  • server must be the same as used in the withSonarQubeEnv (in my example it is equal to "SonarQube")
  • scanner tool must be the same as used in the tool (in my example it is equal to "SonarQubeScanner3")

You also have to check checkbox Enable injection of SonarQube server configuration as build environment variables.

agabrys
  • 8,728
  • 3
  • 35
  • 73
  • thanks, but point is if BlueOcean can show logs we need a declarative syntax script of SonarQube for its Jenkins file, where as i have tried like almost 6-8 different procedures(sharing above) to call it but neither one works. – Ali Khawar Feb 02 '18 at 05:32
  • As I wrote BuleOcean is a persentaion layer and your problem is related to Declarative Pipeline or Scripted Pipeline. – agabrys Feb 02 '18 at 18:51
  • thanks for helping i have tried exactly the same procedure you suggested but by ouput is giiving an error can you please help me with it : `java.lang.NullPointerException org.jenkinsci.plugins.workflow.steps.ToolStep$Execution.run(ToolStep.java:150) org.jenkinsci.plugins.workflow.steps.ToolStep$Execution.run(ToolStep.java:133) – Ali Khawar Feb 08 '18 at 05:40
  • Are you sure that SonaRube step produces the error? Please edit your question and all important data (stacktrace. full pipeline script, configuration screen shots etc.) – agabrys Feb 08 '18 at 15:32
  • This almost works, you need to use see script step (see here: https://stackoverflow.com/questions/42763384/unknown-stage-section-withsonarqubeenv) and don't forget your sonar-project.properties file at the root of your project – Anna Ira Hurnaus Mar 26 '18 at 15:20
  • @agabrys do you know how can i tick that "Enable injection..." after i deploy jenkins and it installing the plugin? – ALex Mar 12 '19 at 14:44
1

it is solved one just need to check the tool location in general tool configs and give the path adn call it in jenkins file.

 stage('PDNS-UI-Sonar') { 
         environment {
             SONAR_SCANNER_OPTS = "-Xmx2g"
             } 
         steps {
             sh "pwd"
             sh "/opt/sonar-scanner/bin/sonar-scanner -Dproject.settings=sonar-project.properties"
             }
         }

enter image description here

mwhs
  • 5,878
  • 2
  • 28
  • 34
Ali Khawar
  • 41
  • 1
  • 1
  • 5