Centos 7 gitlab-ci自動化導入フロントエンドプロジェクト

1935 ワード

  • 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 ciciフォルダに所属グループを追加chmod 755 ci/deploy.shスクリプト実行権限を追加.