1. 程式人生 > 其它 >Bitbucket +Jenkins+SonarQube設定

Bitbucket +Jenkins+SonarQube設定

Bitbucket +Jenkins+SonarQube設定

  1. 流程圖

a)     

為了提高程式碼質量 搭建了這一套掃描工具

 

一、          Bitbucket 設定

  1. 專案管理員在倉庫設定->Webhooks頁面,點選[建立webhook]
    1. 【名稱】自定義
    2. 【URL】http://<您的jenkins訪問路徑>/generic-webhook-trigger/invoke?token=token&name=xxx

1)      token由jenkins生成 見下方

2)      name用於標識是哪個專案,可以自定義別的引數

二、          Jenkins 設定

  1. 外掛安裝
    1. SonarQube Scanner for Jenkins
    2. Generic Webhook Trigger Plugin
    3. 系統設定
      1. SonarQube servers設定

1)     

2)      在URL 填寫伺服器地址,【Server authentication token】填寫 在SonarQube servers 生成的token

  1. 外掛設定 Global Tool Configuration
    1. SonarQube Scanner安裝過程比較麻煩

1)      嘗試從Maven安裝 失敗

2)      嘗試從https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.4.0.2170-linux.zip

下載安裝失敗,上伺服器發現已經下載解壓,只是路徑錯誤

3)      把解壓路徑直接填寫到輸入框成功

  1. 專案設定
    1. 構建觸發器

1)     

2)     

Token生成看下方

3)     

匹配對應資料才執行$name就是上面的name,還可以匹配hook event 裡面的資料

  1. 構建

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

 

 

  1. 生成token
    1. 首頁->使用者列表>點選使用者名稱->點選設定  API Token 可以生成Token

三、          SonarQube設定

  1. 生成token
    1. 在使用者管理 安全頁面生成token
    2. 建立專案

四、          參考

  1. https://www.msy.plus/2021/09/04/jenkins-webhook/