About Runner

Gitlab Runner is an open-source CI/CD deployment tool developed by Gitlab official team based on Golang, supporting Linux, macOS, and Windows. With it, our development process can become more smooth and controllable.

Installation on CentOS

# Add official repository
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash

# Install
sudo yum install gitlab-runner

Register Runner

sudo gitlab-runner register

Runtime platform                                    arch=amd64 os=linux pid=1947 revision=5a147c92 version=11.11.1
Running in system-mode.                            
                                                   
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
https://gitlab.example.com/ # Replace with your Gitlab server address (check in repository settings or admin backend)

Please enter the gitlab-ci token for this runner:
UYXe4zr928H51rUSze4t # Replace with the Token generated by your Gitlab server (check in repository settings or admin backend)

Please enter the gitlab-ci description for this runner:
[server]: Special server # Description of the Runner

Please enter the gitlab-ci tags for this runner (comma separated):
develop,preview # Runner tags, which can be used in .gitlab-ci.yml configuration to select which Runner to execute Pipelines on
Registering runner... succeeded                     runner=UYXe7zr9

Please enter the executor: docker, ssh, virtualbox, docker+machine, kubernetes, docker-windows, docker-ssh, parallels, shell, docker-ssh+machine:
shell # Choose execution method
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

Runners List

About Execution Methods

Shell

This method will execute the script configured in .gitlab-ci.yml on the server where Gitlab Runner is installed in Shell mode. If you just want to use Gitlab Runner to automatically pull the latest code, you can use this method.

stages: 
  - deploy

deploy:
  stage: deploy
  script:
    - commands to execute
  tags:
    - production
gitlab-runner install --working-directory /var/local --user root

When installing the service above, I manually specified the working directory, so it will create a <working-directory>/builds/<short-token>/<concurrent-id>/<namespace>/<project-name> directory structure. This way, every time a developer PUSHes code to the master branch, Runner will pull the latest code to that directory. All that’s left to do is configure the Nginx site root directory to that folder.

I hope this is helpful, Happy hacking…