Jenkins Declarative Pipeline step for running the Scanner


(Ilya Vassilevsky) #1

Hello :slight_smile:

It would have been awesome to be able to use a ready-made step for running the Scanner instead of the script step.


steps {
    script {
        def scannerHome = tool 'TOOL_NAME';
        withSonarQubeEnv('SERVER_NAME') {
            sh "${scannerHome}/bin/sonar-scanner"


steps {
    sonarqube 'TOOL_NAME', 'SERVER_NAME'

The parameters could be optional if there are only one tool or server defined in Jenkins.

Unfortunately, I cannot code Java (only Ruby), so I cannot send you a pull request for this. Please let me know if I can help in any other way.

(Ilya Vassilevsky) #2

Okay I’ve compacted this to the following working code:

withSonarQubeEnv("SERVER_NAME") {
    sh "${tool("TOOL_NAME")}/bin/sonar-scanner"

Still not very pretty tho :slight_smile: