如果說 Tools 是 Jenkins 的手腳,那麼 Plugins 就是它的神經網絡。
透過Plugins,Jenkins 才能與外部的 GitLab、SonarQube 或 Docker 聯動。
本篇將介紹如何配置核心外掛與建立嚴格的安全性憑證管理。
進入 Manage Jenkins -> Plugins -> Available Plugins 搜尋並安裝以下插件:
Git, GitLab Plugin):讓 Jenkins 能感知 GitLab 的 Webhook 並拉取程式碼。MSBuild, NodeJS Plugin, Docker Pipeline):提供特定語言環境的封裝,其中 Docker Pipeline 允許我們在容器內執行建置,確保環境的潔淨與一致性。SonarQube Scanner, Sonar Quality Gates):這是本專案的核心,負責與 SonarQube Server 對接並獲取「品質門檻」結果。HashiCorp Vault, Credentials Binding):確保敏感金鑰不會出現在 Pipeline 日誌中,實現「秘密不落地」。Pipeline: Stage View, Role-based Authorization Strategy):提供可視化的流程進度,並落實權限控管。進入 Manage Jenkins -> Credentials -> System -> Global credentials 建立憑證。
SSH Username with private key)Deploy-Server-Key
root
Secret text)SonarQube-Token
Manage Jenkins -> System。Add SonarQube。
SonarQube (此名稱將用於 withSonarQubeEnv 指令)。https://ci-cd.example.com/sonarqube。SonarQube-Token。Enable injection of SonarQube environment variables。
$SONAR_HOST_URL),減少手動傳參的繁瑣與出錯率。GitLab-Official。https://gitlab.com。GitLab API Token(由 GitLab User Settings -> Access Tokens 生成),這將用於 Jenkins 自動向 GitLab 報告建置狀態(Build Status)。進入 Manage Jenkins -> Security,將 Authorization 改為 Role-Based Strategy。
Dev_ 開頭的專案,有效落實最小權限原則(PoLP)。完成外掛與安全性配置後,Jenkins 已經不再是一個孤島,而是具備了與整個開發生態系溝通的能力。然而,對於使用 SonarQube 社群版的團隊來說,預設不支援多分支分析是一個痛點。下一章,我們將介紹如何透過外掛突破這項限制。