Jenkins与Sonar-Scanner集成

时间:2019-12-28 16:19:30

标签: jenkins sonarqube sonarqube-scan

我正在尝试将Jenkins和声纳扫描仪集成在一起以运行Angular代码。下面是我的设置和配置。

源代码可用路径:/ home / user / Angular SonarQube配置的路径:/ opt / SonarQube Sonar-Scanner配置的路径:/ opt / Sonar-Scanner

$ /opt/SonarQube/bin/. /sonar.sh start

SonarQube正在运行,我可以使用端口号在浏览器中访问本地主机。

http://localhost:9000

接下来,我将使用以下命令在终端中运行声纳扫描仪

sonar-scanner -X -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin

INFO: Analysis report uploaded in 552ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=app
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AW9NPXPGP93qcNh5qcv5
INFO: Analysis total time: 39.071 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 41.826s
INFO: Final Memory: 12M/44M
INFO: ------------------------------------------------------------------------

以下是Jenkins配置

1)管理Jenkins –>全局工具配置–> SonarQube扫描仪已配置,请找到随附的图像。sonar-scanner Jenkins configuration

2)在Jenkins中配置SonarQube服务器,这将传达SonarQube Server身份验证。

登录您的SonarQube服务器,然后在用户栏下找到以下内容 转到我的帐户–>安全性–>生成令牌

Sonar-server token jenkins authentication

现在的问题是,我正在运行jenkins管道作业以在管道阶段使用以下命令执行声纳扫描仪

stage('sonar-scanner') {
        container('sonar') {
           // sh "/sonar-scanner/bin/sonar-scanner -X -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin"
        }
      }

请在下面找到以下jenkins错误日志,它似乎无法访问localhost:9000

+ sonar-scanner -X
09:25:46.052 INFO: Scanner configuration file: /usr/lib/sonar-scanner/conf/sonar-scanner.properties
09:25:46.060 INFO: Project root configuration file: NONE
09:25:46.142 INFO: SonarQube Scanner 4.0.0.1744
09:25:46.143 INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
09:25:46.143 INFO: Linux 5.0.0-1027-azure amd64

09:25:46.568 DEBUG: keyStore is : 
09:25:46.573 DEBUG: keyStore type is : pkcs12
09:25:46.573 DEBUG: keyStore provider is : 
09:25:46.573 DEBUG: init keystore
09:25:46.575 DEBUG: init keymanager of type SunX509
09:25:46.822 DEBUG: Create: /root/.sonar/cache
09:25:46.824 INFO: User cache: /root/.sonar/cache
09:25:46.824 DEBUG: Create: /root/.sonar/cache/_tmp
09:25:46.827 DEBUG: Extract sonar-scanner-api-batch in temp...
09:25:46.830 DEBUG: Get bootstrap index...
09:25:46.831 DEBUG: Download: http://sonarqube:9000/batch/index
09:25:46.893 ERROR: SonarQube server [http://sonarqube:9000] can not be reached
09:25:46.893 INFO: ------------------------------------------------------------------------
09:25:46.894 INFO: EXECUTION FAILURE
09:25:46.894 INFO: ------------------------------------------------------------------------

请您提出一些解决方法,因为整个团队都在考虑这个问题,这真的很有帮助。

0 个答案:

没有答案