[英]Jenkins Pipeline and SonarQube setup
I'm having some trouble setting up SonarQube using Maven on a Jenkins Pipeline. 我在Jenkins Pipeline上使用Maven设置SonarQube时遇到一些麻烦。
My pipeline pulls the git repo into the directory created for it and it goes through the rest of the steps successfully but I don't see the test results on SonarQube nor any output that tests are being ran. 我的管道将git repo拉入为其创建的目录中,并成功完成了其余步骤,但是我没有看到SonarQube上的测试结果,也没有看到正在运行测试的任何输出。
Here is my code set up on the pipeline: 这是我在管道上设置的代码:
node('master'){
stage('Git Clone') {
dir('my-git-dir'){
git branch: '$GIT_BRANCH'
git url: '$GIT_REPO'
credentialsId: '11111111-111-1111-1111-111111111111'
}
}
stage('build & SonarQube Scan') {
MVN="/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.3.9/bin/mvn"
echo "running clean verify sonar"
"$MVN clean verify sonar:sonar -Dsonar.host.url=http://111.11.1.111:9000 -Dsonar.java.binaries=/etc/sonarqube"
echo "running clean install"
"$MVN clean install deploy -DskipTests"
}
}
The command runs just fine on a free style project: 该命令在自由样式项目上运行良好:
#!/usr/bin/bash
MVN="/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.3.9/bin/mvn"
$MVN clean verify sonar:sonar -Dsonar.host.url=http://111.11.1.111:9000 -Dsonar.java.binaries=/etc/sonarqube
$MVN clean install deploy -DskipTests
It also has an "Invoke top-level Maven targets" Maven Version: 它还具有“调用顶级Maven目标” Maven版本:
Maven 3.3.9
Goals: 目标:
test
-fn
Edit: Working Script 编辑:工作脚本
stage('SonarQube analysis') {
dir("$gitRepo"){
withSonarQubeEnv('SonarQube') {
sh "pwd"
MVN="/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.3.9/bin/mvn"
echo "Running JaCoCO stuff"
sh "$MVN clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=false"
echo "running clean verify"
sh "$MVN clean verify sonar:sonar -Dsonar.host.url=http://111.11.1.111:9000" //-Dsonar.java.binaries=/etc/sonarqube"
echo "running clean install deploy"
sh "$MVN clean install deploy -DskipTests"
}
PS I am trying to create a job that you can select a repo and branch to pull from, create/use a file in that workspace to run SonarQube on PS我正在尝试创建一个作业,您可以选择要从中回购和分支的作业,在该工作区中创建/使用文件以在其上运行SonarQube
Your question demonstrates several misunderstandings. 您的问题表明了一些误解。
First, SonarQube analysis will not execute your tests for you; 首先,SonarQube分析不会为您执行测试; you need to fire that off yourself.
您需要自己开除。 As noted in the docs the command for that would be something like
如文档中所述,该命令类似于
$MVN clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=false
followed by 其次是
$MVN sonar:sonar -sonar.host.url=http://111.11.1.111:9000
Note that I've left off the -Dsonar.java.binaries=/etc/sonarqube
parameter you used. 请注意,我没有使用您使用的
-Dsonar.java.binaries=/etc/sonarqube
参数。 That's because 那是因为
/etc/sonarqube
. /etc/sonarqube
。 (Move them if they are.)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.