How to execute SonarQube scanner in Jenkins Declarative Pipeline without Maven and Docker

断了今生、忘了曾经 提交于 2019-12-08 06:22:11

问题


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'
        }
      }
    }
  }
}

回答1:


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:

and SonarQube scanner in Manage Jenkins → Global Tool Configuration → 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.




回答2:


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



来源:https://stackoverflow.com/questions/48557886/how-to-execute-sonarqube-scanner-in-jenkins-declarative-pipeline-without-maven-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!