首页 文章

在gitlab CI中,gitlab运行器选择了错误的 Actuator

提问于
浏览
0

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

我认识到在bash中显示了“shell runner”但在.yml文件中我使用了“tags:-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

有任何想法吗?

1 回答

  • 1

    @edit:来自here

    标签用于从允许运行此项目的所有Runner列表中选择特定的Runners .

    正如在注释中解决的那样,执行的shell必须使用 docker 标记进行标记,这导致他被选为作业的执行者 .

    这是我的老答案:

    您正在使用shell执行程序,并且来自here

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

    您正在运行的命令作为 gitlab-runner 用户执行,并且无权运行 apt-get 命令 . 您可以:

    • 移动到码头 Worker

    • 授予用户gitlab-runner运行指定命令所需的权限 . gitlab-runner可能run apt-get without sudo,他也需要perpm for npm install和npm run .

    • 将sudo nopasswd授予用户gitlab-runner . 在机器上添加 gitlab-runner ALL=(ALL) NOPASSWD: ALL (或类似)到/ etc / sudoers gitlab-runner并将行 apt-get update 更改为 sudo apt-get update ,它们将以特权用户(root)的身份执行它们 .

相关问题