1gittlab,配置本地Git.
2 添加項目到CI(Continues Integration)中
ci-01.png
3 單擊項目,進入CI頁面中
第一次沒有配置的情況下:
ci-02.png
4 添加".gitlab-ci.yml"檔案
".gitlab-ci.yml"檔案放在倉庫的根目錄下,用來設定gitlab項目的runner,每次在push的時候自動觸發項目的build。
首先在項目的根目錄下(git clone ...)建立'.gitlab-ci.yml'檔案,針對建立的示例項目建立簡單的内容:
stages:
- build
- test
- deploy
b1:
stage: build
script:
- uname -a
- g++ hello.cpp
- bash scripts
tags:
- shell
t1:
stage: test
script:
- ./a.out
tags:
- shell
檔案包含多個stage,如build、test、deploy,每個相同的stage運作都是并行的,而後面的stage必須在前面的stage運作結束才能開始。script表示運作指令,示例中以shell指令為例。tags表示runner的标簽,用哪個runner來build項目,關于runner的配置在下一章中。
另外,在build完項目後,可以添加一個腳本用來進行測試程式,如'-bash scripts'。
添加檔案"hello.cpp"和".gitlab-ci.yml",然後push到gitlab。
$git add hello.cpp .gitlab-ci.yml
$git commit -a
$git push origin master
成功之後,commit的狀态為"pending",意思是正在等待中,因為還沒有runner來執行。
轉存失敗重新上傳取消
image
關于檔案格式内容的詳細說明.gitlab-ci.yml
5 配置Runner
單擊網頁左側Runners。
ci-03.png
有"Specific runners"和"Shared runners"兩種,我們隻介紹"Specific runners"的配置,關于runner的詳細說明。在Spcific runners中有紅色的URL和token,這兩個資料在配置runner時會用到。
1.安裝runner
$sudo apt-get update
$sudo apt-get install gitlab-ci-multi-runner
詳細安裝及Docker的安裝
2.配置runner
注冊runner,操作時會要求輸入上文提到的URL和token,這裡我們runner的執行程式用的是shell,是以在excutor選擇shell。指令如下:
$sudo gitlab-ci-multi-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci )
http://gitlab.###.io/ci
Please enter the gitlab-ci token for this runner
########################
Please enter the gitlab-ci description for this runner
my-runner
INFO[0034] fcf5c619 Registering runner... succeeded
Please enter the executor: shell, docker, docker-ssh, ssh?
shell
INFO[0037] Runner registered successfully. Feel free to start it, but if it's
running already the config should be automatically reloaded!
配置成功後,我們的項目狀态如下,變為running:
ci-04.png
之後運作順利的話,會出現綠色标志: