1.准备好 gitlab 和 token
工程 --> Settings --> CI/CD --> Runners
2.注册 Runner
Runner 需要注册到 Gitlab 才可以被项目所使用,一个 gitlab-ci-multi-runner 服务可以注册多个 Runner。
sudo gitlab-ci-multi-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://gitlab.zousiliang.com/
Please enter the gitlab-ci token for this runner:
F4vbKHg1bzZTwLDa3Uxz
Please enter the gitlab-ci description for this runner:
[VM_25_0_centos]:
Please enter the gitlab-ci tags for this runner (comma separated):
test,demo
Whether to run untagged builds [true/false]:
[false]:
Whether to lock Runner to current project [true/false]:
[false]:
Registering runner... succeeded runner=F4vbKHg1
Please enter the executor: parallels, virtualbox, docker+machine, docker, docker-ssh, docker-ssh+machine, kubernetes, shell, ssh:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
3.配置构建任务
- 在项目根目录添加.gitlab-ci.yml 文件
关于该文件的各项配置请见
- 示例:
# 定义 stages
stages:
- build
- test
- deploy
# 定义 job
job1:
stage: test
tags:
- demo
script:
- echo "I am job1"
- echo "I am in test stage"
# 定义 job
job2:
stage: build
tags:
- demo
script:
- echo "I am job2"
- echo "I am in build stage"
job3:
stage: deploy
tags:
- demo
script:
- echo "I am job3"
- echo "I am in deploy stage"
- 执行结果
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于