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.
More on Integrations: SonarQube, Nexus, Artifactory, Docker, Trivy
How does `waitForQualityGate` work?IntermediateHow do you deploy Maven artifacts to Nexus from Jenkins?IntermediateHow do you publish npm packages or pull dependencies through Nexus or Artifactory?BeginnerHow do you use JFrog Artifactory from Jenkins?IntermediateHow do you build and push a Docker image from Jenkins on a VM agent?BeginnerHow do you scan an image with Trivy in a pipeline and gate on results?Intermediate