gitlab-ci

GitLab CI/CD

GitLab提供了持續(xù)集成服務(wù),對于每次提交或推送以觸發(fā)您的CI管道,您必須:

  • 將.gitlab-ci.yml文件添加到存儲庫的根目錄中
  • 確保將項目配置為使用Runner

安裝 Runner

https://packages.gitlab.com/runner/gitlab-runner?page=3
根據(jù)自己的系統(tǒng),選擇Debian或者rpm類型安裝包
例如,CentOS系統(tǒng),就選擇rpm,執(zhí)行

curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
yum install gitlab-runner

配置 Runner

1.執(zhí)行下列命令

sudo gitlab-runner register

2.輸入 GitLab 實例 URL:

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com

3.輸入項目token(可以在Settings->CI/CD->Runners中獲取):

Please enter the gitlab-ci token for this runner
xxx
  1. 輸入Runner的描述
Please enter the gitlab-ci description for this runner
[hostname] my-runner

5.輸入Runner的tag:

Please enter the gitlab-ci tags for this runner (comma separated):
my-tag,another-tag

6.輸入Runner executor,一般選擇shell就可以:

Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
docker

7.如果您選擇Docker作為執(zhí)行程序,系統(tǒng)會要求您提供默認(rèn)鏡像,以用于未在.gitlab-ci.yml中定義的項目中:

Please enter the Docker image (eg. ruby:2.6):
alpine:latest

編寫 .gitlab-ci.yml 并提交到根目錄下

例如筆者的一個Java項目

stages:
  - prepare
  - compile
  - check
  - package

job1:
  stage: compile
  tags:
    - codecheck
  script:
    - source /etc/profile
    - mvn clean compile -s settings.xml

job2:
  stage: package
  tags:
    - codecheck
  script:
    - source /etc/profile
    - mvn clean package -DskipTests -s settings.xml
 
job3:
  stage: prepare
  tags:
    - codecheck
  script:
    - echo "hello world!"
    - ls -al
    - pwd
    - whoami
    - uname -a
 
chekstyle:
  stage: check
  allow_failure: true
  tags:
    - codecheck
  script:
    - mvn checkstyle:check -s settings.xml

findbugs:
  stage: check
  tags:
    - codecheck
  script:
    - mvn findbugs:check -s settings.xml

pmd:
  stage: check
  tags:
    - codecheck
  script:
    - mvn pmd:check -s settings.xml

執(zhí)行結(jié)果

批注 2020-02-15 212643.jpg
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容