gpt4 book ai didi

sonarqube - 如何为SonarQube扫描配置Jenkins管道

转载 作者:行者123 更新时间:2023-12-04 17:16:25 24 4
gpt4 key购买 nike

我正在尝试为我的项目配置jenkins管道,但是如果有人可以指导我做错了什么,这里会丢失一些东西:

下面是管道脚本:

node {
stage('SonarQube analysis') {
// requires SonarQube Scanner 2.8+
def scannerHome = tool 'sonarScanner';
withSonarQubeEnv('SonarQube 6.2') {
bat "${scannerHome}/bin/sonar-runner.bat"
}
}
}

以下是Jenkins Sonar插件的相关配置:
Manage Jenkins > Configure System下:
enter image description here

Manage Jenkins > Global Tool Configuration
enter image description here

以下是我得到的错误:
D:\jenkins\workspace\Test_Pipeline>D:\sonar-runner-2.4/bin/sonar-runner.bat
D:\sonar-runner-2.4
SonarQube Runner 2.4
Java 1.8.0_92 Oracle Corporation (64-bit)
Windows Server 2008 R2 6.1 amd64
INFO: Runner configuration file: D:\sonar-runner-2.4\conf\sonar-runner.properties
INFO: Project configuration file: NONE
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: D:\jenkins\workspace\Test_Pipeline\.\.sonar
INFO: SonarQube Server 6.2
19:48:53.627 INFO - Load global repositories
19:48:53.920 INFO - Load global repositories (done) | time=298ms
19:48:53.951 WARN - Property 'sonar.jdbc.url' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.
19:48:53.951 WARN - Property 'sonar.jdbc.username' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.
19:48:53.951 WARN - Property 'sonar.jdbc.password' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.
19:48:53.951 INFO - User cache: C:\Users\Administrator\.sonar\cache
19:48:54.378 INFO - Load plugins index
19:48:54.378 INFO - Load plugins index (done) | time=0ms
19:48:55.235 INFO - Process project properties
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 3.404s
Final Memory: 5M/120M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.sources
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
[Pipeline] }
[Pipeline] // wrap
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

问题似乎是 Jenkins 不知道我的sonar-project.properties放在哪里。它在D:\myprj下,内容如下:
# required metadata
sonar.projectKey=my_prj:my_prj
sonar.projectName=my_prj
sonar.projectVersion=1.00
sonar.sources=my_prj/src
sonar.language=java

请建议我如何使Jenkins管道了解sonar-project.properties文件的放置位置

最佳答案

我需要将工作空间添加到脚本中。这是下面的脚本:

stage('SonarQube analysis') {
ws('D:\\my_prj') {
// requires SonarQube Scanner 2.8+
def scannerHome = tool 'sonarScanner';
withSonarQubeEnv('SonarQube 6.2') {
bat "${scannerHome}/bin/sonar-scanner.bat"
}
}
}

关于sonarqube - 如何为SonarQube扫描配置Jenkins管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41513527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com