Automatically deploy the code above git to the server

Keywords: GitLab Docker sudo shell

1. Configure gitlab runner on the computer

Reference document https://docs.gitlab.com/runner/install/osx.html

Installation:

 sudo curl --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64

add permission

 sudo chmod +x /usr/local/bin/gitlab-runner

Start up

 cd ~
 gitlab-runner install
 gitlab-runner start

2. Gitlab runner is associated with the code base, that is, the registration phase.

Reference documents https://docs.gitlab.com/runner/register/index.html

 sudo gitlab-runner register

Note: enter the following two addresses and Tokens:

 

 Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
 Please enter the gitlab-ci token for this runner

These can be input by myself. For example, I input plus-h5-static-release-dev.

Please enter the gitlab-ci description for this runner
 [hostname] plus-h5-static-release-dev

tag I entered dev

 Please enter the gitlab-ci tags for this runner (comma separated):
 dev

I chose shell script here

 Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
 shell 

After configuration, check git. If the following runner appears, it indicates success.

 

Then configure. gitlab-ci.yml in the root directory of the project.

The example is as follows: where, / users / zhileilei / code / server code / is my customized directory, which can be modified to the path where I want to store it.

before_script:
  - echo "this is before script"
stages:
  - build
job:
  stage: build
  script:
    - echo "building"
    - path=`pwd`
    - echo $path
    - cp -rf $path/* /Users/zhaileilei/code/server-code/
  tags:
    - dev
  after_script:
    - echo $path

At this point, you can submit the code in the code base and check whether the pipeline is successful.

Click the success or failure button under the States to view the specific command execution or error message.

At this point, the commit to server configuration is complete.

 

Upgrade the configuration. Note that only the dev-0522, Dev and test branches are valid, and the master is not.

before_script:
  - echo "this is before script"
  # Before executing the command, clear the contents of the folder to be accessed by the pre sending server. If there is no file, create a new one.
  - cd /Users/zhaileilei/code/server-code/ && /bin/rm -rf *
stages:
  - build
job:
  stage: build
  only:
    # Only the code from these branches is automatically deployed
    - dev-0522
    - dev
    - test
  except: 
    - master
  script:
    - echo "building"
    - path=`pwd`
    - echo $path
    - cp -rf $path/* /Users/zhaileilei/code/server-code/
  tags:
    - dev
  after_script:
    - echo $path
    # Clear the contents of the file in the default read location after executing the command
    - cd $path && /bin/rm -rf *

 

Posted by the_loser on Mon, 21 Oct 2019 07:41:24 -0700