我的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 回答
@edit:来自here:
正如在注释中解决的那样,执行的shell必须使用
docker
标记进行标记,这导致他被选为作业的执行者 .这是我的老答案:
您正在使用shell执行程序,并且来自here:
您正在运行的命令作为
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)的身份执行它们 .