在 gitlab CI 中,gitlab runner 选择了错误的执行者 [英] In gitlab CI the gitlab runner choose wrong executor

查看:65
本文介绍了在 gitlab CI 中,gitlab runner 选择了错误的执行者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Gitlab 管道设置存在以下问题.

I have the following problem with my Gitlab Pipeline Setup.

我认识到在 bash 中显示了shell runner",但在 .yml 文件中我使用了tags: -docker".如果我重新运行这项工作,有时它会起作用并使用正确的跑步者,但大多数时候不是.

I recognized that in the bash there is shown "shell runner" but in the .yml file I used "tags: -docker". If I re-run the job, sometimes it works and uses the right runner, but most of the time not.

这是 bash 输出:

The is the bash output:

使用 gitlab-runner 10.8.0 (079cad9e) 运行在 aws-xyz c444133a 上使用 Shell 执行器...在 ip-xyz 上运行...正在获取更改...HEAD 现在位于 eb4ea13 xyz:已删除数据重试队列检查 e0461c05 作为后端测试...跳过 Git 子模块设置正在检查 default-1 的缓存...成功提取缓存$ echo "这是在每一步之前完成的"这是在每一步之前完成的$ echo "更新容器内的服务器软件"更新容器内的服务器软件$ apt-get 更新 -y正在阅读包裹清单...W:目录/var/lib/apt/lists/partial 的 chmod 0700 失败 - SetupAPTPartialDirectory(1:不允许操作)E: 无法打开锁定文件/var/lib/apt/lists/lock - open (13: Permission denied)E: 无法锁定目录/var/lib/apt/lists/W:取消链接文件/var/cache/apt/pkgcache.bin 时出现问题 - RemoveCaches(13:权限被拒绝)W:取消链接文件/var/cache/apt/srcpkgcache.bin 时出现问题 - RemoveCaches(13:权限被拒绝)在脚本之后运行...$ echo "这是在每一步之后完成的"这是在每一步之后完成的错误:作业失败:退出状态 1

这是 gitlab-ci.yml 文件中的作业:

This is the job in the gitlab-ci.yml file:

后端测试:图片:节点:6服务:- 名称:mysql:5.7阶段:测试变量:MYSQL_ROOT_PASSWORD: xyzMYSQL_DATABASE: xyzMYSQL_USER: xyzMYSQL_PASSWORD: xyz数据库方言:mysql数据库数据库:xyz数据库用户:xyz数据库密码:xyz数据库主机:mysql数据库端口:3306"脚本:- echo更新容器内的服务器软件"- apt-get 更新 -y- apt-get 升级 -y- 回显安装依赖项"- cd api/后端/-ls -lah- npm 安装- 回声开始测试"- NODE_ENV=test npm run test-code-coverage标签:- 码头工人

有什么想法吗?

推荐答案

@edit: From 这里:

@edit: From here:

tags 用于从允许运行该项目的所有 Runners 列表中选择特定的 Runners.

tags is used to select specific Runners from the list of all Runners that are allowed to run this project.

正如评论中所解决的那样,您执行的 shell 必须带有 docker 标记,这导致他被选为作业的执行者.

As resolved in the comments, your shell executed must have been tagged with the docker tag, which resulted in him being picked as the executor for the job.

这是我的旧答案:

您正在使用 shell 执行程序,并从 这里:

You are using a shell executor, and from here:

Shell 执行器是一个简单的执行器,它允许您在安装了 Runner 的机器上本地执行构建
...
如果 GitLab Runner 从官方的 .deb 或 .rpm 包安装在 Linux 上,安装程序将尝试使用 gitlab_ci_multi_runner 用户(如果找到).如果没有找到,它将创建一个 gitlab-runner 用户并使用它来代替.....
在某些测试场景中,您的构建可能需要访问一些特权资源
...
通常使用 shell 执行器运行测试是不安全的.这些作业以用户的权限 (gitlab-runner) 运行,并且可以从在此服务器上运行的其他项目中窃取"代码.仅用于在您信任和拥有的服务器上运行构建.

Shell executor is a simple executor that allows you to execute builds locally to the machine that the Runner is installed
...
If GitLab Runner is installed on Linux from the official .deb or .rpm packages, the installer will try to use the gitlab_ci_multi_runner user if found. If it is not found, it will create a gitlab-runner user and use this instead. ....
In some testing scenarios, your builds may need to access some privileged resources
...
Generally it's unsafe to run tests with shell executors. The jobs are run with the user's permissions (gitlab-runner) and can "steal" code from other projects that are run on this server. Use it only for running builds on a server you trust and own.

您正在运行的命令是以 gitlab-runner 用户身份执行的,并且没有运行 apt-get 命令的权限.你可以:

The commands your are running are executed as gitlab-runner user and don't have permissions to run apt-get command. You can:

  • 移至码头
  • 授予用户 gitlab-runner 运行指定命令所需的权限.gitlab-runner 可能在没有sudo的情况下运行apt-get,他也需要npm的perms安装并 npm 运行.
  • 将 sudo nopasswd 授予用户 gitlab-runner.将 gitlab-runner ALL=(ALL) NOPASSWD: ALL (或类似的)添加到安装 gitlab-runner 的机器上的/etc/sudoers 并更改行 apt-get updatesudo apt-get update,它将以特权用户 (root) 身份执行它们.
  • move to docker
  • grant user gitlab-runner the permissions he needs to run specified commands. gitlab-runner may run apt-get without sudo, also he will need perms for npm install and npm run.
  • grant sudo nopasswd to user gitlab-runner. Add gitlab-runner ALL=(ALL) NOPASSWD: ALL (or similar) to /etc/sudoers on the machine gitlab-runner is installed and change the lines apt-get update to sudo apt-get update, which will execute them as privileged user (root).

这篇关于在 gitlab CI 中,gitlab runner 选择了错误的执行者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆