gitlab CI/CD环境搭建
程序员文章站
2022-04-30 08:39:32
...
1.安装gitlab-runner
# Linux x86-64
sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
sudo chmod +x /usr/local/bin/gitlab-runner
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
以上是Linux64位环境下的安装,其他的环境参考 https://docs.gitlab.com/runner/install/linux-manually.html
2.注册gitlab-runner
sudo gitlab-runner register
他会提示你写gitlab的地址和token,这地址可以在gitlab的网页上的settings->CI/CD Pipelines 找到如图:
另外,配置好的runner可能需要开启-Run untagged jobs,同样在上图所示的页面中有一个Runners activated for this project列表,点击下面runner右侧的修改按钮,在页面中把 Run untagged jobs勾选即可
其他具体参考:https://docs.gitlab.com/runner/register/index.html
3.在项目根目录中添加 .gitlab-ci.yml 如下:
# 提交dev分支时触发
dev job:
only:
- dev
script:
- echo 'dev' >> ci.log
# 提交test分支时触发
test job:
only:
- test
script:
- ssh aaa@qq.com -i /home/gitlab-runner/.ssh/ci_key << ssh2
- date >> ci.log
- cd /home/ubuntu/first_project/
- git checkout test
- git pull origin test
- ssh2
# 提交master分支时触发
master job:
only:
- master
script:
- ssh aaa@qq.com -i /home/gitlab-runner/.ssh/ci_key << ssh2
- date >> ci.log
- cd /home/ubuntu/first_project/
- git checkout master
- git pull origin master
- ssh2
然后,本地提交代码后runner就会执行.yml里相关脚本
上一篇: DevOps与阿里云容器服务(三)
下一篇: 编程与数学(一):计算玩家面对面
推荐阅读
-
centos下GitLab+Jenkins持续集成环境搭建(安装jenkins)
-
centos下GitLab+Jenkins持续集成环境搭建(安装jenkins)
-
基于Docker+K8S+GitLab/SVN+Jenkins+Harbor搭建持续集成交付环境的详细教程
-
Gitlab Pipeline+Supervisor Python项目CI/CD实战 (二)
-
Gitlab Pipeline+Supervisor Python项目CI/CD环境搭建(一)
-
基于Docker部署GitLab环境搭建的方法步骤
-
使用GitLab+Jenkins实现持续集成CI环境的示例代码
-
jenkins基于gitlab实现CI/CD
-
Docker搭建自己的Gitlab CI Runner
-
Gitlab CI/CD