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
- 輸入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