安装 gitlab CI 服务.md
安装 gitlab-ce
安装依赖包
yum install curl policycoreutils openssh-server openssh-clients systemctl enable sshd systemctl start sshd yum install postfix systemctl enable postfix systemctl start postfix firewall-cmd --permanent --add-service=http systemctl reload firewalld
下载 gitlab-ce 镜像
vim /etc/yum.repos.d/gitlab-ce.repo [gitlab-ce] name=Gitlab CE Repository baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/ gpgcheck=0 enabled=1 yum makecache yum install gitlab-ce
配置
vi /etc/gitlab/gitlab.rb
external_url 'http://ip'
启动gitlab
gitlab-ctl reconfigure
遇到报错
Error executing action `run` on resource 'execute[semodule -i /opt/gitlab/embedded/selinux/rhel/7/gitlab-7.2.0-ssh-keygen.pp]
- stop gitlab
- yum install libsemanage-static libsemanage-devel
安装CI服务
下载安装CI
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7/gitlab-runner-10.5.0-1.x86_64.rpm rpm -ivh gitlab-runner-10.5.0-1.x86_64.rpm sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash gitlab-runner uninstall gitlab-runner install --working-directory /home/gitlab-runner/ --user gitlab-runner gitlab-runner restart gitlab-runner status
注册 runner
sudo gitlab-ci-multi-runner register -- 输入Gitlab CI地址, (e.g. https://gitlab.xunlei.cn/ci) http://192.168.1.249/gitlab/ -- 输入项目CI token fuXXXXXXXXXX -- 输入 Runner 描述(e.g. home.xl9.xunlei.com 测试runner) 测试Runner -- 输入 Runner 标签,可以多个,用逗号隔开(e.g. 10.10.34.91-dev) 251-dev -- 输入 Runner 执行的语言 (e.g. shell) shell -- 认证是否注册成功 sudo gitlab-ci-multi-runner verify
编写脚本
在项目下面创建.gitlab-ci.yml
stages: - deploy deploy_dev: stage: deploy tags: - 251-dev only: - develop script: - deploy_stage.sh
然后在部署服务器上的 gitlab-runner
用户路径下创建deploy_stage.sh
echo "delete old xyj-admin-api" sudo rm -rf /raid1/www/test sudo git clone [email protected]:test/xyj-test-api.git /raid1/www/test sudo git fetch --all sudo git reset --hard origin/test echo "=============重启服务====================" source /etc/profile sudo supervisorctl restart test time=`date` echo "部署结束: $time." echo "================================================"
其中 测试项目是被 supervisorctl
管理的
要确保几件事
- 改服务器能够正常从远端克隆数据
- 命令几点要带上
sudo
- 用户
sudo
无密码及在tty下可以使用需要参考 Linux sudo 相关操作 - 如果克隆下来的文件放在挂载盘,需要在 ~/ 路径下执行 clone 然后放到对应路径,否则报错
fatal: could not create work tree dir
遇到无法克隆,且 gitlab 日志为
gitlab JWT::DecodeError (Nil JSON web token)
修改 nginx 配置
upstream gitlab-workhorse { server unix:/var/opt/gitlab/gitlab-workhorse/socket; } ... proxy_pass http://gitlab-workhorse; ...
git push develop 后触发脚本
相关推荐
cxin 2020-11-06
synshitou 2020-10-21
Topbeyond 2020-08-21
happyfreeangel 2020-07-27
白开水 2020-07-19
无风的雨 2020-07-08
贤时间 2020-07-06
wishli 2020-06-28
小信 2020-06-21
leehbhs 2020-06-20
happyfreeangel 2020-06-18
83284950 2020-06-17
冯冯领队 2020-06-16
就是那个胖子 2020-06-14
83284950 2020-06-14
LiHansiyuan 2020-06-14
fcds00 2020-06-11
就是那个胖子 2020-06-11