你用什么用户启动gitlab-runner,那么执行的时候,代码就在该用户的家目录。
gitlab-ci触发以后,gitlab-runner就会把代码获取到/home/gitlab-runner/builds,例如我的:
[root@centos3 consumerBanking]# pwd
/home/gitlab-runner/builds/aa766057/0/soa/consumerBanking
[root@centos3 consumerBanking]# ls
pom.xml src
下面是yml的内容:
image.png
创建test文件并提交,触发gitlab-ci.yml:
image.png
触发之后就开始做mvn打包动作:
image.png
回到gitlab-runner服务器:
[root@centos3 consumerBanking]# ll
total 16
-rw-rw-r--. 1 gitlab-runner gitlab-runner 775 Sep 2 19:49 pom.xml
drwxrwxr-x. 4 gitlab-runner gitlab-runner 4096 Sep 2 19:49 src
drwxrwxr-x. 7 gitlab-runner gitlab-runner 4096 Sep 2 23:23 target
-rw-rw-r--. 1 gitlab-runner gitlab-runner 4 Sep 2 23:23 test
target就是mvn打的包,并且刚刚创建的test文件也获取到了。然后这里可以痛过scp将包传到web服务器的指定目录。
如果想调用脚本,可以将脚本写好后,将啊的path添加到/etc/profile 中,例如:
[root@centos3 consumerBanking]# vim /etc/profile
export PATH=/home/gitlab-runner/.local/bin:$PATH
[root@centos3 consumerBanking]# vim /home/gitlab-runner/.local/bin/deploy
#!/bin/bash
echo "fafadfasdhgafgafg"
这样就相当于命令,只需要这样就可以调用了:
image.png