gitlab自动化部署CI案例

 参考:html

http://www.javashuo.com/article/p-hdgxdpdp-dn.html   (简单操做)java

http://www.javashuo.com/article/p-zvmbdlnd-eb.html  (详细操做)git

http://www.javashuo.com/article/p-ttejewie-ev.html   (gitlab、gitlab-CI、runner的关系)shell

一、工程代码准备:
gitlab上新建root3组,新建print123工程,工程根目录下配置yml文件.gitlab-ci.ymlbash

gitlab上新建gitlab-runner帐号,创建和服务器的ssh免密登陆。服务器

二、yml文件(gitlab代码上):ssh

stages:
- deploy
deploy:
  stage: deploy
  script:
    - deploy root3 print123
  only:
    - master
  tags:
    - shell

  

三、deploy文件(Linux上):gitlab

#!/bin/bash
if [ $# -ne 2 ]
then
      echo "arguments error!"
      exit 1
else
      deploy_path="/var/www/$1/$2"
      if [ ! -d "$deploy_path" ]
      then
              project_path="git@10.2.3.4:"$1/$2".git"
              git clone $project_path $deploy_path
      else
              cd $deploy_path
              git pull
      fi
fi

  

四、runner注册:post

gitlab-ci-multi-runner register    #  注册一个新的runner

  

延伸:
gitlab-ci-multi-runner status
gitlab-ci-multi-runner stop
gitlab-ci-multi-runner start
gitlab-ci-multi-runner verify # 查看全部runner
gitlab-runner verify --delete # 删除无效的runner.net

注册用到内容:

http://10.2.3.4:8881/         #  在gitlab上查询
Juyx-L5433amkQKSo2XQ          #  在gitlab上查询
deploy_description5
shell               # tags要和yml文件中的tags保持一致
true
回车

  

五、修改print123中的文件,push提交,在gitlab的pipeline中观察是否pass

相关文章
相关标签/搜索