# sudo gitlab-ci-multi-runner register
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci):
http://192.168.1.2/ci // 在这里输入gitlab安装的服务器ip/ci 即可
Please enter the gitlab-ci token for this runner:
eaYyokc57xxZbzAsoshT // 这里的token可通过Gitlab上的项目Runners选项查看,在下面贴一张截图
Please enter the gitlab-ci description for this runner:
[i-ujhmwrcf]: spring-demo // 这里填写一个描述信息,不太重要,看着填吧
Please enter the gitlab-ci tags for this runner (comma separated):
demo // 在这里填写tag信息,多个tag可通过逗号,分割。
Whether to run untagged builds [true/false]:
[false]:true // 此处我选择的是true,不然每次push还得弄tag
Whether to lock Runner to current project [true/false]:
[false]: // 默认
Registering runner... succeeded runner=TrJhrjxc
Please enter the executor: docker, docker-ssh, parallels, shell, ssh, virtualbox, docker+machine, docker-ssh+machine:
shell // 在这里需要输入runner的执行方式,因为我的Gitlab和runner是安装在同一台服务器上的,直接输入shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
当注册好 Runner 之后,可以用 sudo gitlab-ci-multi-runner list 命令来查看各个 Runner 的状态:
记得要Whether to run untagged builds [true/false]:选择true,不然触发时会卡住~ 理论上建立完毕之后就会部署一次,可在项目路径下Pipelines--->Pipelines里面查看部署过程。
修改gitlab-runer获取代码的位置(默认获取代码位置:/home/gitlab-runner/builds)
# 定义 stages
stages:
- build
- test
# 定义 job
job1:
stage: test
script:
- echo "I am job1"
- echo "I am in test stage"
# 定义 job
job2:
stage: build
script:
- echo "I am job2"
- echo "I am in build stage"
写起来很简单吧!用 stages 关键字来定义 Pipeline 中的各个构建阶段,然后用一些非关键字来定义 jobs。
每个 job 中可以可以再用 stage 关键字来指定该 job 对应哪个 stage。job 里面的 script 关键字是最关键的地方了,也是每个 job 中必须要包含的,它表示每个 job 要执行的命令。
回想一下我们之前提到的 Stages 和 Jobs 的关系,然后猜猜上面例子的运行结果?
I am job2
I am in build stage
I am job1
I am in test stage
根据我们在 stages 中的定义,build 阶段要在 test 阶段之前运行,所以 stage:build 的 jobs 会先运行,之后才会运行 stage:test 的 jobs。