Centos7 gitlab-ci 自动化部署前端项目

  • 添加Gitlab-runner官网仓库: curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
  • 安装gitlab-runner: yum install gitlab-runner
  • 注册 gitlab-runner: gitlab-runner register
[root@VM_222_128_centos ~]# gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=7978 revision=003fe500 version=12.7.1
Running in system-mode.                            
                                                   
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://gitlab.xxx.com/       你的gitlab站点域名
Please enter the gitlab-ci token for this runner:
CYLo7aJR3X-VFvf_o1Ba  / 项目的token, 在点开项目->设置/ci_cd/runner->展开就可以看到了。
Please enter the gitlab-ci description for this runner:
自动化        
Please enter the gitlab-ci tags for this runner (comma separated):
web_deploy   // 标签,在后续的.gitlab-ci.yml中使用
Registering runner... succeeded                     runner=CYLo7aJR
Please enter the executor: docker+machine, kubernetes, docker, docker-ssh, shell, ssh, custom, parallels, virtualbox, docker-ssh+machine:
shell    // 选择shell方式
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 
  • gitlab-runner start 启动gitlab-runner

  • 在前端代码根目录创建: .gitlab-ci.yaml文件:

web_deploy:
    script:
        - ci/deploy.sh

    only:
        - master

    stage: deploy

    tags:
        - web_deploy
  • 创建一个ci文件夹,并创建一个deploy.sh脚本:
#!bin/bash
cd  /xxxx/目录   服务器的代码目录
git pull
rm -rf dist 删除原来的dist文件夹
npm install 安装依赖
npm run build:prod 构建
  • chown gitlab-runner:gitlab-runner ci,给ci文件夹添加所属组, chmod 755 ci/deploy.sh添加脚本执行权限。

你可能感兴趣的:(git,Linux)