Jenkins Shared Library Integration Without Installing SonarPlugin

I have requirements to integrate SonarQube with Jenkins using a generic Jenkins Shared Library. I was also told not to install the SonarQube plugin in Jenkins UI. My question is? Is this possible and without using the plugin am I losing any functionality. Thank you!

Hey there.

You’ll have to orchestrate downloading the scanner and setting the configuration (URLs, secrets) all by yourself, which is more complex and error prone than using the Jenkins scanner.

Why the hesitation to install he official integration?

Hi Colin,

They are averse to plugins in general and prefer to avoid. So I need to research how to build as a Jenkins Shared Library.

You mentioned some steps - are they documented anywhere? downloading the scanner and setting the configuration (URLs, secrets).

I see an example from the documentation of a Jenkins pipeline to override variables. Assume these variables would be required? SONAR_HOST_URL, SONAR_AUTH_TOKEN
What else?

withSonarQubeEnv('My SonarQube Server', envOnly: true) {
  // This expands the evironment variables SONAR_CONFIG_NAME, SONAR_HOST_URL, SONAR_AUTH_TOKEN that can be used by any script.
  println ${env.SONAR_HOST_URL} 
}

Thanks a lot!

If you really need to build something yourself, I would reccomend consulting the documentation on the SonarScanner – specifically running from the zip file. It mentions sonar.host.url and sonar.login, which you would need to pass the information that would usually be provided by withSonarQubeEnv.

And… I think you introduce more risk building something homegrown rather than using something open-source like the plugins (SonarSource/sonar-scanner-jenkins). The code is freely available on GitHub.