Phabricator集成Jenkins-配置篇

1、安裝插件:

根據github上面的phabricator-jenkins-plugin插件readme文件進行配置。

在Jenkins安裝插件頁面搜索phabricator-jenkins-plugin插件並且安裝:

1.1、Phabricator新加bot賬號配置

  1. 在Phabricator用戶管理中創建一個bot賬號:

    在創建界面中需要填寫郵箱地址,因爲此賬號會自動通過驗證,如果沒有可用的郵箱了,可以僞造一個郵箱地址。
  2. 通過管理員身份進入Phabricator用戶管理界面,選擇剛剛創建的用戶 --> Manage --> Edit Setting,點擊Conduit API Tokens,然後點擊Generate Token按鈕生成一個token:

    並且複製該token,下一步會用到。

1.2、Jenkins配置

進入Jenkins系統配置界面(https://ci.example.com/configure,替換成實際域名),跳到Phabricator配置區域,點擊添加按鈕進行添加Jenkins憑證提供者:

彈出表單如下:

按照如上表單進行填寫,其中類型選擇Phabricator Conduit Key,Phabricator URL填寫您的Phabricator系統的實際訪問地址,Conduit Token填寫上一步複製的token,點擊保存即可生成Jenkins訪問Phabricator的憑證。

注意,爲了能夠讓Jenkins正確訪問到對應的代碼倉庫,您同事需要給上一步配置的bot賬號授權訪問代碼倉庫。

2、使用

2.1、新建Jenkins Job

2.1.1、新建Phabricator代碼評審前自動化構建測試Job

Job名稱設置爲:mvn_automated_construction_test

在Jenkins管理界面中添加一個Job(或者修改現有的Job集成Phabricator),然後點擊Configure按鈕,進入配置界面。

參數化構建過程:

勾選參數化構建過程,分別添加一下參數:

  • project 倉庫地址 字符類型
  • git_url 倉庫方位地址 字符類型
  • token Jenkins的口令 字符類型
  • commit_id git提交hash串
  • DIFF_ID
  • PHID

Build Triggers

參數化構建過程中的token需要在Jenkins裏面配置好,爲了支持通過token訪問Jenkins系統,您需要安裝[Build Token Root Plugin](https://wiki.jenkins.io/display/JENKINS/Build+Token+Root+Plugin),並且在Build Triggers中設置token:

Source Code Management

Source Code Management配置區域:由於我們統一使用Git倉庫,這裏選擇Git

Repositories:

  • Repository URL:$git_url
  • Credentials:這裏需要新增一個Jenkins憑證,類型選擇SSH Username with private key,把私鑰添加進去,添加完成之後,這裏選擇剛剛添加到憑證即可,配置界面參考如下附圖。

Branches to build:

  • Branch Specifier (blank for ‘any’):$commitId

Additional Behaviours:

  • Check out to a sub-directory:$project(爲倉庫代碼創建子文件夾)

Build Environment

勾選Apply Phabricator Differential

Work directory填寫:$project

注意,2.0.2版本的phabricator plugin有bug,不支持參數化構建過程,Work directory只能填寫具體的目錄地址,爲了修復這個bug,如果需要支持參數化構建,需要手工修復下,修復後的插件地址:

Pre Steps

添加執行 shell

這裏簡單的填寫提示腳本:

cd $WORKSPACE/$project
echo "using commitId:"$commitId

Build

Root POM:./${project}/pom.xml
Goals and options:clean install -U

Post-build Actions

Post to Phabricator

  • Comment on Success 勾選
  • Comment with console link on Failure 勾選
  • Add Custom Comment:file_name(如果您需要自定義Jenkins在Phabricator Revision中的評論,這裏可以填寫自定義評論文件的文件名,對應的文件需要存放在Jenkins workspace目錄下Job的文件夾裏面)

2.1.2、新建Phabricator代碼land到代碼倉庫之後觸發自動化構建Job

Job名稱設置爲:mvn_commit_automated_construction

整體配置與新建Phabricator代碼評審前自動化構建測試Job配置類似,在創建該Job的時候,可以直接從新建Phabricator代碼評審前自動化構建測試Job複製一份。

Pre Steps

添加執行 shell

內容:

cd $WORKSPACE/${project}
echo "using commit id:"$commitId
git clean -xdf
git checkout .
git reset --hard $commitId

Build

Goals and options:clean install -U

或者如果,您正在編譯到是jar項目,可以執行deploy到私服:

Goals and options:clean deploy

2.2、Phabricator中Harbormaster配置

首先需要在Phabricator中添加Harbormaster配置,該配置會通過Herald規則觸發,後續會對配置進行說明。

2.2.1、添加Maven自動化構建測試

  1. 進行Harbormaster配置:https://phabricator.example/harbormaster/plan/(替換成實際域名)
  2. 點擊Create Build Plan
  3. 輸入build plan的名稱,這裏我們輸入:提交代碼審查觸發自動化構建測試
  4. 然後點擊Create Build Plan
  5. 進入Maven自動化構建測試的Build Plan,點擊Add Build Step按鈕
  6. 點擊選擇Make HTTP Request

其中
URI的配置

http://phabricator.example/job/mvn_automated_construction_test/buildWithParameters?token=token_abtest&DIFF_ID=KaTeX parse error: Expected 'EOF', got '&' at position 17: …buildable.diff}&̲PHID={target.phid}&git_url=KaTeX parse error: Expected 'EOF', got '&' at position 17: …repository.uri}&̲project={repository.callsign}&commitId=${buildable.commit}

注意,域名要替換爲phabricator的實際域名,job名稱要替換爲實際的名稱,token要設置爲您在job的配置界面中設置的實際的token值

When Complete:選擇Wait on Message

2.2.2、添加land提交代碼後自動構建

配置與上一步類似,build plan名稱可以設置爲提交代碼觸發自動化構建其中URI有所區別:

http://phabricator.example/job/mvn_commit_automated_construction/buildWithParameters?token=token_abtest&DIFF_ID=KaTeX parse error: Expected 'EOF', got '&' at position 17: …buildable.diff}&̲PHID={target.phid}&git_url=KaTeX parse error: Expected 'EOF', got '&' at position 17: …repository.uri}&̲project={repository.callsign}&commitId=${buildable.commit}

注意job的名稱爲:mvn_commit_automated_construction

2.3、Phabricator中Herald的配置

2.3.1、配置提交代碼評審觸發自動化構建

  1. 進行Herald配置:https://phabricator.example/herald/(替換成實際域名)
  2. 點擊Create Herald Rule
  3. New Rule for選擇Differential Revisions繼續
  4. Role Type選擇Global
  5. 進入配置表單

Rule Name可以配置爲:Maven自動化構建測試

假設我們想讓遊戲引擎組項目組項目的所有倉庫都執行提交代碼審查後觸發自動化構建,則具體配置規則:

When all of these conditions are met:

Repository projects include any of 遊戲引擎組
Take these actions every time this rule matches:

Run build plans: Plan 3 提交代碼審查觸發自動化構建測試.

2.3.2、配置land代碼到倉庫之後觸發自動化構建規則

與上一步類似,注意New Rule for選擇Commit,具體配置規則:

When all of these conditions are met:

Repository projects include any of 遊戲引擎組
Take these actions every time this rule matches:

Run build plans: Plan 2 提交代碼觸發自動化構建.

首次發表於:Phabricator集成Jenkins-配置篇

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章