iT邦幫忙

1

關於SonarQube分析到資料卻沒有code的問題 (感謝 fillano 協助解決)

  • 分享至 

  • twitterImage

這是我的Jenkins Build Log

Started by user root
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/Sonar
using credential gitlab
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url http://root@172.16.16.63/root/scott.git # timeout=10
Fetching upstream changes from http://root@172.16.16.63/root/scott.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials gitlab
 > git fetch --tags --progress http://root@172.16.16.63/root/scott.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision e4278f02b998f688476def1681a1b83d2c59fede (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f e4278f02b998f688476def1681a1b83d2c59fede
Commit message: "java 003"
 > git rev-list --no-walk e4278f02b998f688476def1681a1b83d2c59fede # timeout=10
Injecting SonarQube environment variables using the configuration: admin
[Sonar] $ /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar_scanner/bin/sonar-scanner -Dsonar.host.url=http://172.16.16.23:9000/ -Dsonar.projectName=JackySonar -Dsonar.projectVersion=1.0 -Dsonar.sourceEncoding=UTF-8 -Dsonar.projectKey=Sonar -Dsonar.dynamicAnalysis=false -Dsonar.sources=/var/lib/jenkins/workspace/Sonar/Jacky003.class -Dsonar.projectBaseDir=/var/lib/jenkins/workspace/Sonar
INFO: Scanner configuration file: /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonar_scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 4.0.0.1744
INFO: Java 1.8.0_212 Oracle Corporation (64-bit)
INFO: Linux 3.10.0-957.el7.x86_64 amd64
INFO: User cache: /var/lib/jenkins/.sonar/cache
INFO: SonarQube server 7.1.0
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Publish mode
INFO: Load global settings
INFO: Load global settings (done) | time=100ms
INFO: Server id: AWwXwu9HiPzPiWQqqBxi
INFO: User cache: /var/lib/jenkins/.sonar/cache
INFO: Load plugins index
INFO: Load plugins index (done) | time=129ms
INFO: Load/download plugins
INFO: Load/download plugins (done) | time=220ms
INFO: Process project properties
INFO: Load project repositories
INFO: Load project repositories (done) | time=404ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=18ms
INFO: Load active rules
INFO: Load active rules (done) | time=1377ms
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=136ms
INFO: Project key: Sonar
INFO: Project base dir: /var/lib/jenkins/workspace/Sonar
INFO: -------------  Scan JackySonar
INFO: Load server rules
INFO: Load server rules (done) | time=247ms
INFO: Base dir: /var/lib/jenkins/workspace/Sonar
INFO: Working dir: /var/lib/jenkins/workspace/Sonar/.scannerwork
INFO: Source paths: Jacky003.class
INFO: Source encoding: UTF-8, default locale: en_US
INFO: Index files
INFO: 1 file indexed
INFO: Sensor SonarJavaXmlFileSensor [java]
INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=1ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=70ms
INFO: Sensor CPD Block Indexer
INFO: Sensor CPD Block Indexer (done) | time=0ms
INFO: Calculating CPD for 0 files
INFO: CPD calculation finished
INFO: Analysis report generated in 1138ms, dir size=23 KB
INFO: Analysis reports compressed in 120ms, zip size=5 KB
INFO: Analysis report uploaded in 69ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://172.16.16.23:9000/dashboard/index/Sonar
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://172.16.16.23:9000/api/ce/task?id=AWwYV20XiPzPiWQqqCrj
INFO: Task total time: 8.938 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 12.139s
INFO: Final Memory: 11M/142M
INFO: ------------------------------------------------------------------------
Finished: SUCCESS

由上面可以知道,Jenkins確實有掃到資料並傳送到SonarQube中 (如下圖)
https://ithelp.ithome.com.tw/upload/images/20190722/201145201muZd5VzG6.png

但是查看SonarQube發現,確實有資料傳輸進來,但資料內容卻都是「零」

https://ithelp.ithome.com.tw/upload/images/20190722/20114520jFHmr5fiZM.pnghttps://ithelp.ithome.com.tw/upload/images/20190722/201145204vfCq6dN66.png

研究不少天了,目前看起來SonarQube和Jenkins是有通的,但似乎沒撈到資料

該筆資料內容為

https://ithelp.ithome.com.tw/upload/images/20190722/201145209mNam9T3t8.pnghttps://ithelp.ithome.com.tw/upload/images/20190722/20114520OIrzFC3oRK.png

看更多先前的討論...收起先前的討論...
fillano iT邦超人 1 級 ‧ 2019-07-22 14:50:07 檢舉
https://docs.sonarqube.org/latest/analysis/analysis-parameters/ 看一下sonar.sources的說明,似乎只能指定路徑而不是檔案?

另外,靜態分析不是分析編譯好的.class檔而是原始碼,你應該放.java檔才對。
踏雪尋梅 iT邦研究生 5 級 ‧ 2019-07-22 15:02:27 檢舉
!!真想給您一個最佳解答

我換了.java就解決了,確實有掃到資料了,感恩

※ sonar.sources,我指定檔案,也能成功
fillano iT邦超人 1 級 ‧ 2019-07-22 15:30:44 檢舉
我只是看你build log推測,沒有仔細研究,所以不好發回答啦,將就將就...
踏雪尋梅 iT邦研究生 5 級 ‧ 2019-07-22 15:40:57 檢舉
我覺得自己太菜了,一個簡單的東西,扣掉假日,我卡了兩天,被您一語道破!!
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答