The first step: Find a machine, if there is no curl command, execute the installation command:
sudo apt-get install curl
Step 2: Install gitlab runner on the machine and execute the command:
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
# 这里安装gitlab-runner 只是下载了一个二进制文件,会造成一个问题,当机器关机或者重启,再次启动gitlab-runner的时候,gitlab-runner启动报错,可以把这个当成一次性服务的东西,类似于docker,
# 如果想一劳永逸解决这个问题,sudo apt-get install gitlab-runner
Note: The machine system and version are different, and the runner installed is also different. For details, please refer to the official:
https://docs.gitlab.com/runner/install/
Step 3: Grant its execution permissions
sudo chmod +x /usr/local/bin/gitlab-runner
Step 4: Create a gitlab CI user
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
--comment 'xxxxx'
'xxxxx'代表注解
如果想要设置用户名和密码,用例如下:
--comment 'xxxxx' xw --password 123456
xw 代表用户名
123456 代表暗文密码(我认为设不设置都可以,后期可以更改可以使用的密码)
查看所有用户密码:sudo cat /etc/shadow
但是我们看到的123456是加密后的,若想改成能够使用的密码,sudo passwd xu
接下来输入密码
--create-home
创建用户目录
Step 5: Install and run as a service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
# 关闭 gitlab-runner服务:sudo gitlab-runner stop
Step 6: Check the running status of gitlab-runner
sudo gitlab-runner status
Step 7: Register runner
sudo gitlab-runner register
The result after executing the registration command,
and then enter the CI/CD Runner in the corresponding git project setting to view the result: it
indicates that the association has been successful. At this time, add the .gitlab-ci.yml file to the project
注意:
如果CI/CD的job一直是Pending状态,需要做以下操作:
For example, perform flake8 code specification checks:
stages:
- pep8
- build
# PEP8 检查
pep8:
stage: pep8
script:
- flake8
When the code is standardized: When the
code is not standardized:
Even if such a basic CI process is completed, the CI process will be checked automatically every time the code is updated.