SonarQube_Server與Scanner安裝

SonarQube 常見操作與安裝

資訊

以下是 sonarqube-10.0.0.68432 版本,後續主要使用9.9版安裝步驟大同小異這邊就不另外說明。

Operating the server (sonarqube.org)

# 針對SonarQube進行安裝到Windows Service(重新啟動後會自動開啟服務)
> E:\SonarQube\sonarqube-10.0.0.68432\bin\windows-x86-64\SonarService.bat install

# 啟動
> E:\SonarQube\sonarqube-10.0.0.68432\bin\windows-x86-64\SonarService.bat start
> E:\SonarQube\sonarqube-10.0.0.68432\bin\windows-x86-64\SonarService.bat stop
> E:\SonarQube\sonarqube-10.0.0.68432\bin\windows-x86-64\SonarService.bat status

> ```

### 設定檔案

> 修改設定檔案必須重新啟動SonarQube Server才會生效
> 環境變數:如果使用環境變數,遇到`.`或`-`,都用底線`_`代替。`sonar.web.systemPasscode` use `SONAR_WEB_SYSTEMPASSCODE`

#### 資料庫設定

如果要使用Windows帳號登入,需要設定Integrated_Security,以及下載相對應的套件,詳細可參考[Install the database](https://docs.sonarqube.org/latest/setup-and-upgrade/install-the-server/#installing-the-database),因為我這邊沒使用到,所以直接在連線字串設定`integratedSecurity=false`或不設定

如果要使用windows驗證登入資料庫,需要下載
https://github.com/microsoft/mssql-jdbc/releases/download/v11.2.2/mssql-jdbc_auth.zip

#### sonar.properties 設定

```yml

# User credentials.
# Permissions to create tables, indices and triggers must be granted to JDBC user.
# The schema must be created first.
sonar.jdbc.username=<Your SonarQube Account>
sonar.jdbc.password=<Your SonarQube Password>

# Use the following connection string if you want to use SQL Auth while connecting to MS Sql Server.
# Set the sonar.jdbc.username and sonar.jdbc.password appropriately.
sonar.jdbc.url=jdbc:sqlserver://<Yout DB IP>;databaseName=sonar;encrypt=false;user=<YourAccount>;pw=<YourPassword>

安裝


.\bin\windows-x86-64\SonarService.bat install

ERROR: java.exe not found. Please make sure that the environmental variable SONAR_JAVA_PATH points to the Java executable.

# 這邊我放在 E
setx SONAR_JAVA_PATH "E:\SonarQube\jdk-17.0.7\bin\java.exe"

D:\software\sonarqube-11.0.0.68432\jdk-17.0.7\bin
PS E:\SonarQube\sonarqube-10.0.0.68432> .\bin\windows-x86-64\SonarService.bat install
2023-06-06 14:07:02,403 INFO  - Installing service 'SonarQube (SonarQube)'...
2023-06-06 14:10:41,057 INFO  - Service 'SonarQube (SonarQube)' was installed successfully.

E:\SonarQube\sonarqube-10.0.0.68432\bin\windows-x86-64\SonarService.bat start

Download the Microsoft Build of OpenJDK | Microsoft Learn

Debug


# 測試運作是否成功,如果有錯誤訊息都會出現在Console上
> E:\SonarQube\sonarqube-10.0.0.68432\bin\windows-x86-64\StartSonar.bat

Log檔案描述

MSSQL設定問題

com.microsoft.sqlserver.jdbc.SQLServerException: 驅動程式無法使用安全通訊端層 (SSL) 加密建立與 SQL Server 的安全連接。錯誤: "PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"。 ClientConnectionId:998bd79a-a1d6-4e61-8ced-7f65c64e2b00

主要是設定MSSQL 連線字串要加入帳號密碼。

``sonar.jdbc.url=jdbc:sqlserver://127.0.0.1;databaseName=sonar;encrypt=false;user=;pw=

資料庫定序設定問題

nested exception is Database collation must be case-sensitive and accent-sensitive. It is Chinese_Taiwan_Stroke_CI_AS but should be Chinese_Taiwan_Stroke_CS_AS

觀察 Web.log 發現關鍵字,了解是因為建立資料庫的時候定序的問題,根據ChatGPT的回應 200-Areas/210-工程師修煉/SQL/Case-sensitive200-Areas/210-工程師修煉/SQL/Accent-sensitive

解決方法

  1. 建立完資料庫後, 選項 --> 定序 --> 選擇 Chinese_Taiwan_Stroke_CS_AS

200-Areas/210-工程師修煉/SonarQube/resource/SonarQube_Server安裝.png|1000

成功

第一次安裝完成後,預設帳密為:admin/admin

200-Areas/210-工程師修煉/SonarQube/resource/SonarQube_Server安裝-1.png|900

小插曲

第一次啟動過程中,訊息一值卡在 Registar Rule,過了一小時之後就好了也很妙,但目前測試都可以正常運作

Scanner 安裝

警告

結果一值無法在10版本之中進行分析,所以嘗試 sonarqube-9.9.1.69595 版的就可以了

官方文件選擇自己的專案版本即可,目前專案.net Freamwork 4.6為主力,Scanner過程中還是需要依賴MsBuild.exe建立專案,如果有安裝 VS可以自己找相關路徑,沒有的話可以到微軟下載

Scanner就是一個壓縮檔案,主要是SonarScanner.MSBuild.exe這個執行檔,後續要把整包放置要建立的伺服器當中(考量未來整合GitLab,我會建議直接放置在GitLab Runner伺服器)

後續閱讀

List
from "200-Areas/210-工程師修煉/SonarQube"
where dg-publish = true
sort file.ctime