Interview Prep/Jenkins/Integrations: SonarQube, Nexus, Artifactory, Docker, Trivy

How do you integrate SonarQube with a Jenkins pipeline?

IntermediateConceptIntegrations: SonarQube, Nexus, Artifactory, Docker, Trivy
Answer

Install the SonarQube Scanner plugin, configure the server (name, URL, token credential) under System or via JCasC (unclassified.sonarGlobalConfiguration), then:

stage('SonarQube') {
  steps {
    withSonarQubeEnv('sonarqube') {
      sh 'sonar-scanner -Dsonar.projectKey=shack-app -Dsonar.sources=src -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info'
    }
  }
}

withSonarQubeEnv injects SONAR_HOST_URL, SONAR_AUTH_TOKEN and SONARQUBE_SCANNER_PARAMS, which the scanner reads automatically. For Maven use mvn -B sonar:sonar.

All Jenkins questions Roadmap: Jenkins

More on Integrations: SonarQube, Nexus, Artifactory, Docker, Trivy