Bitbucket +Jenkins+SonarQube設定
Bitbucket +Jenkins+SonarQube設定
- 流程圖
a)
為了提高程式碼質量 搭建了這一套掃描工具
一、 Bitbucket 設定
- 專案管理員在倉庫設定->Webhooks頁面,點選[建立webhook]
- 【名稱】自定義
- 【URL】http://<您的jenkins訪問路徑>/generic-webhook-trigger/invoke?token=token&name=xxx
1) token由jenkins生成 見下方
2) name用於標識是哪個專案,可以自定義別的引數
二、 Jenkins 設定
- 外掛安裝
- SonarQube Scanner for Jenkins
- Generic Webhook Trigger Plugin
- 系統設定
- SonarQube servers設定
1)
2) 在URL 填寫伺服器地址,【Server authentication token】填寫 在SonarQube servers 生成的token
- 外掛設定 Global Tool Configuration
- SonarQube Scanner安裝過程比較麻煩
1) 嘗試從Maven安裝 失敗
3) 把解壓路徑直接填寫到輸入框成功
- 專案設定
- 構建觸發器
1)
2)
Token生成看下方
3)
匹配對應資料才執行$name就是上面的name,還可以匹配hook event 裡面的資料
- 構建
1)
2) # projectKey 用sonar設定好的專案id
sonar.projectKey=ppms
# --- optional properties ---
# defaults to project key
#sonar.projectName=ppms
# defaults to 'not provided'
#sonar.projectVersion=1.0
sonar.language=c#
# Path is relative to the sonar-project.properties file. Defaults to .
#sonar.sources=$WORKSPACE
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
- 生成token
- 首頁->使用者列表>點選使用者名稱->點選設定 API Token 可以生成Token
三、 SonarQube設定
- 生成token
- 在使用者管理 安全頁面生成token
- 建立專案
四、 參考
- https://www.msy.plus/2021/09/04/jenkins-webhook/