The company's Gitlab has always had a corresponding runner available, but after the recent machine migration, no one has rebuilt the runner . So, I borrowed a virtual machine to install Gitlab runner to do CI.
Prerequisite operating Environment:CentOS 7 gitlab version: gitlab Community Edition 8.12.4 The user used by the installation process: root
The approximate steps are as follows:
Add repository (add the repository)
Curl-l https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash
Install Gitlab-ci-multi-runner (Install gitlab-ci-multi-runner)
Yum Install Gitlab-ci-multi-runner
Register runner (Register the runner)
1. If you want to register multiple runner on the same machine, you only need to perform this step repeatedly.
2. If you want to process multiple builds at the same time, you need to enter the/ETC/GITLAB-RUNNER/CONFIG.TOML file configuration concurrent its value is >1 value
Gitlab-ci-multi-runner Register please
enter the GITLAB-CI coordinator URL (e.g. https://gitlab.com)
https:// gitlab.com Please
enter the Gitlab-ci token for this runner
xxx Please enter the
gitlab-ci description for Thi S runner
My-runner
info[0034] fcf5c619 registering runner ... succeeded please
enter the Executor:shell Docker, Docker-ssh, ssh?
Docker please
enter the docker image (eg. ruby:2.1):
ruby:2.1
info[0037] Runner registered. Feel free to start it, but if it's
running already the config should be automatically reloaded!
For the above steps, please refer to the official instructions
The Gitlab runner installed through the previous steps is the latest version by default and may be incompatible with your Gitlab version. For example, after I installed it, I was prompted not to be compatible:
Gitlab Runner >= 9.0 can be used to with Gitlab Ce/ee >= 9.0
How about that. What else to do, we have to find a match with the Gitlab version of the Gitlab runner , unless you can convince the company to upgrade Gitlab to the latest version of the relevant people. (Anyway in our company this is very difficult ...) )
Fortunately, I found the official installation of the low version description
In this page, it lists the compatibility table of Gitlab and Gitlab runner , based on the contents of the table, I decided to install the 1.10.7 version. (PS: All versions of the list can be seen in the release of Gitlab )
Yum Install Gitlab-ci-multi-runner-1.10.7-1
So the 1.10.7 version of the runner will be installed, and then you just need to perform the register steps above.
In addition, my project is based on maven 's Java Project, as my . Gitlab-ci.yml wrote:
Build:
script:
mvn clean compile-dskiptests
So, obviously, in order for runner to run successfully, we have to install JDK and Mavenon the machine where runner is located.
Here, I recommend that you or the manual installation of these two better. If installed via Yum install MAVEN, the OpenJDKwill be downloaded automatically, which may not be what we want. You think for yourselves.
Finally, it is important to note that when runner runs, it uses the gitlab-runner user. Where did this user come from. It is automatically installed when you yum install Gitlab.
So, we need to configure the environment variable for this gitlab-runner user so that it can execute the mvn variable. For example, my settings are:
# Su-gitlab-runner
# vim ~/.BASHRC
Add the following content
export java_home=/usr/java/jdk1.7.0_80
export Maven_ home=/opt/apache-maven-3.3.9
export path= $PATH: $JAVA _home/bin: $MAVEN _home/bin
export classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar
Save exit (: wq!)
# source ~/.BASHRC
Reference blog Gitlab-ci and Gitlab-runner