era*_*006 2 linux automated-tests docker gitlab-ci gitlab-ci-runner
我的 Gitlab 管道设置存在以下问题。
我认识到在 bash 中显示了“shell runner”,但在 .yml 文件中我使用了“标签:-docker”。如果我重新运行该作业,有时它会起作用并使用正确的运行器,但大多数时候不会。
这是 bash 输出:
Running with gitlab-runner 10.8.0 (079cad9e)
on aws-xyz c444133a
Using Shell executor...
Running on ip-xyz...
Fetching changes...
HEAD is now at eb4ea13 xyz: removed data retry queue
Checking out e0461c05 as backend-tests...
Skipping Git submodules setup
Checking cache for default-1...
Successfully extracted cache
$ echo "this is done BEFORE each step"
this is done BEFORE each step
$ echo "updating server software inside container"
updating server software inside container
$ apt-get update -y
Reading package lists...
W: chmod 0700 of directory /var/lib/apt/lists/partial failed - SetupAPTPartialDirectory (1: Operation not permitted)
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
Running after script...
$ echo "this is done AFTER each step"
this is done AFTER each step
ERROR: Job failed: exit status 1
这是 gitlab-ci.yml 文件中的工作:
backend_test:
image: node:6
services:
- name: mysql:5.7
stage: test
variables:
MYSQL_ROOT_PASSWORD: xyz
MYSQL_DATABASE: xyz
MYSQL_USER: xyz
MYSQL_PASSWORD: xyz
DBDIALECT: mysql
DBDATABASE: xyz
DBUSER: xyz
DBPASSWORD: xyz
DBHOST: mysql
DBPORT: "3306"
script:
- echo "updating server software inside container"
- apt-get update -y
- apt-get upgrade -y
- echo "installing dependencies"
- cd api/backend/
- ls -lah
- npm install
- echo "start testing"
- NODE_ENV=test npm run test-code-coverage
tags:
- docker
有任何想法吗?
@edit:从这里:
标签用于从允许运行此项目的所有运行程序列表中选择特定运行程序。
正如评论中所解决的那样,您执行的 shell 必须被标记为docker标签,这导致他被选为作业的执行者。
这是我的旧答案:
您正在使用 shell 执行器,从这里开始:
Shell executor 是一个简单的执行器,它允许您在安装了 Runner 的机器本地执行构建
......
如果 GitLab Runner 是从官方 .deb 或 .rpm 包安装在 Linux 上,安装程序将尝试使用 gitlab_ci_multi_runner 用户如果找到。如果没有找到,它将创建一个 gitlab-runner 用户并使用它。....
在某些测试场景中,您的构建可能需要访问某些特权资源
...
通常使用 shell 执行程序运行测试是不安全的。这些作业以用户的权限 (gitlab-runner) 运行,并且可以从在此服务器上运行的其他项目中“窃取”代码。仅将其用于在您信任和拥有的服务器上运行构建。
您正在运行的命令是以gitlab-runner用户身份执行的,并且没有运行apt-get命令的权限。你可以:
gitlab-runner ALL=(ALL) NOPASSWD: ALL(或类似)到安装了 gitlab-runner 的机器上的 /etc/sudoers 并将行更改apt-get update为sudo apt-get update,这将作为特权用户(root)执行它们。