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

相關文章
相關標籤/搜索