「GitLab CI/CD」- 常见错误汇总

Runner-related

… prepare environment: Process exited with status 1 …

问题描述:

...
ERROR: Job failed: prepare environment: Process exited with status 1. Check http
s://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more info
rmation
...

环境信息:
GitLab Runner 15.2.2, SSH Executor

原因分析:
https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading

解决方案:
rm -rf $HOME/.bash_logout

… /root/.ssh/known_hosts: no such file or directory …

Types of shells supported by GitLab Runner | GitLab
“ssh: handshake failed: knownhosts: key is unknown” error for VirtualBox executor
SSH | GitLab

问题描述:

Using SSH executor...
ERROR: Preparation failed: ssh command Connect() error: getting host key callback: open /root/.ssh/known_hosts: no such file or directory
Will be retried in 3s ...

环境信息:
GitLab Runner 15.2.2, SSH Executor

原因分析:Introduced in GitLab 14.3. To enable SSH StrictHostKeyChecking, make sure the [runners.ssh.disable_strict_host_key_checking] is set to false. The current default is true. In GitLab 15.0 and later, the default value is false, meaning host key checking is required.

解决方案:

[[runners]]
...
  [runners.ssh]
    disable_strict_host_key_checking = true
...

You are not allowed to download code from this project

Runner can’t pull code from server – GitLab CI/CD – GitLab Forum

在 GitLab CI/CD 中,执行 Pipeline 产生如下错误:

Running with gitlab-runner 12.6.0 (ac8e767a)
  on ci-node Je2FxKTm
Using Docker executor with image python:3.6 ...
Pulling docker image python:3.6 ...
Using docker image sha256:cf1a689bcf55b9c83c397a6aa919ddfd7d05cb12bab4fd6de3c8af5dbc99b798 for python:3.6 ...
Running on runner-2exFJBTm-project-19-concurrent-0 via eec8077625c3...
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/tools/xxxxxxx/.git/
Created fresh repository.
remote: You are not allowed to download code from this project.
fatal: unable to access 'https://git.example.com/tools/xxxxxxx.git/': The requested URL returned error: 403
ERROR: Job failed: exit code 1

问题原因

该问题的原因有很多,我们场景可能仅是其中的一种。

我们的原因是:因为我们是管理员用户,能访问仓库,但是不是仓库成员,所以不能拉取代码(但是我们却能在命令行拉取代码)。

解决方案

将当前用户(执行 Pipeline 用户)加入到该项目中,再次提交构建,此时可以成功构建。