1,搭建好SonarQube平台
2,在搭建好的sonarQube平台添加需要檢測的項目
1) 輸入項目標識和顯示名
2) 創建令牌或者使用已有令牌
3) 輸入令牌后根據項目的開發語言下載相關掃描器
4)前端項目選擇JS,並點擊下載跳轉到 https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/,根據運行系統環境下載相應資源
5)下載后解壓,在系統中添加環境變量,以macOS為例輸入以下命令
1.跳轉到根目錄:cd ~
2.若沒有.bash_profile則先創建文件.bash_profile: touch .bash_profile
3.打開.bash_profile文件:vim .bash_profile
4.在文件夾中指定sonarscaner執行命令的目錄:export PATH=${PATH}:~/fsonarScaner/bin/
5. 保存文件
6.打開之前下載的文件夾conf中的文件sonar-scanner.properties並編輯如下內容並保存:
#----- Default source code encoding
sonar.sourceEncoding=UTF-8
#----- 執行檢測的開發語言
sonar.language=javaScript
#----- SonarQube上已經添加的項目名
sonar.projectKey=project_tag
#----- 當前目錄要分析的路徑地址
sonar.sources=./src
#----- SonarQube掃描結果提交地址
sonar.host.url=https://www.xxx.xxx/cq
#----- SonarQube上項目令牌
sonar.login=令牌
7. 在根目錄執行source .bash_profile使環境變量生效
8.切換到需要檢測的項目目錄。執行命令:sonar-scanner
9.執行結束后可在sonarQube平台查看掃描情況