In the process of getting up to speed with Jenkins pipelines I'm converting some old builds which use the FreeStyle type projects to using Pipelines. The old Freestyle build works well.
My builds are normally done within a container environment (spun up for just that build, over SSH) and ends with a SonarQube analysis for QA.
The sonarqube step (using Jenkins SonarQube plugin) automatically injects the sonarqube scanner with correct arguments into the container to connect to the SonarQube server as seen in this example from the console logs of the Jenkins buid:
22:47:13 Unpacking https://repo1.maven.org/maven2/org/sonarsourc/scanner/cli/sonar-scanner-cli/3.3.0.1492/sonar-scanner-cli-3.3.0.1492.zip to /home/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Aditus_SonarQube on docker-000b7eccw94td on Docker on master 22:47:13 [g7ctrl-server] $ /home/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Aditus_SonarQube/bin/sonar-scanner -Dsonar.host.url=https://myserver.com/sonarqube ******** -Dproject.settings=/home/jenkins/workspace/g7ctrl-server/sonar-project.properties -Dsonar.projectBaseDir=/home/jenkins/workspace/g7ctrl-server 22:47:14 INFO: Scanner configuration file: /home/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Aditus_SonarQube/conf/sonar-scanner.properties 22:47:14 INFO: Project root configuration file: /home/jenkins/workspace/g7ctrl-server/sonar-project.properties 22:47:14 INFO: SonarQube Scanner 3.3.0.1492
Having read Analyzing in a Jenkins pipeline I conclude that it does not apply since the Scanner is not installed. Also reading Execute SonarQube Scanner within Jenkins 2 Pipeline since it assumes the same.
Is there any automation (equivalent to FreeStyle build step) or do I need to write shell-script to download, unpack, and install the scanner manually into the container?
Would appreciate if someone could shed a light on this? (or some best-practice examples - since I'm a rookie on pipeline scripting) I would assume others have faced this issue as well)
Update: (Almost Solved)
Using the snippet generator one could setup standard tools
stage('SonarQube analysis') {
def sonarqubeScannerHome = tool name: 'Aditus SonarQube', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
withSonarQubeEnv('Aditus SonarQube') {
sh "${sonarqubeScannerHome}/bin/sonar-scanner -Dsonar.host.url=https://myserver.com/sonarqube -Dproject.settings=/home/jenkins/workspace/g7ctrl-server/sonar-project.properties -Dsonar.projectBaseDir=/home/jenkins/workspace/g7ctrl-server"
}
}
Defining the tool will trigger Jenkins to download, unpack and install the Scanner Tool. However, despite the project setting parameters being the same as in the freestyle build (that works) the scanner believes the root file is not set as can be seen from the logs
Unpacking https://repo1.maven.org/maven2/org/sonarsource/scanner/cli/sonar-scanner-cli/3.3.0.1492/sonar-scanner-cli-3.3.0.1492.zip to /home/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Aditus_SonarQube on docker-000dsh7hwihbw on Docker on master [Pipeline] sh + /home/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Aditus_SonarQube/bin/sonar-scanner -Dsonar.host.url=https://myserver.com/sonarqube -Dproject.settings=/home/jenkins/workspace/g7ctrl-server/sonar-project.properties -Dsonar.projectBaseDir=/home/jenkins/workspace/g7ctrl-server INFO: Scanner configuration file: /home/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/Aditus_SonarQube/conf/sonar-scanner.properties INFO: Project root configuration file: NONE
Most likely there is a path problem in my lack of mastery of the pipeline scripts that I fail to see. (The scanner is called with identical parameters in both Freestyle & Pipeline case)