对于要部署的某些项目,我有一些gitlab-ci.yml
文件。在将我的头撞在墙上几个小时之后,我意识到它们随机通过/失败。当然,什么都没有改变,只需要按下“重试”按钮,有时作业就会通过,而有时作业会失败。
这是我正在使用的.gitlab-ci.yml
:
image: docker:latest
services:
- docker:dind
before_script:
- echo "Runnig before_script"
- apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make
- pip install docker-compose
stages:
- test
- build
- deploy
test:
stage: test
script:
- echo "Testing the app"
- docker-compose run app sh -c "python /app/manage.py test && flake8"
build:
stage: build
only:
- develop
- production
- feature/deploy-debug-gitlab
script:
- echo "Building the app"
- docker-compose build
deploy:
stage: deploy
only:
- master
- feature/deploy
script:
- echo "Deploying the app"
- docker-compose up -d
environment: production
when: manual
我在那里做错了吗?对我来说似乎很简单。
工作失败 ,我总是会收到错误消息:apk command not found
。就像这里:
Running with gitlab-runner 11.11.1 (5a147c92)
on My Runner Jd5HNvxy
Using Shell executor...
Running on ubuntu-512mb-lon1-01...
Reinitialized existing Git repository in /home/gitlab-runner/builds/Jd5HNvxy/0/<my.name>/<my.app>/.git/
Fetching changes...
Checking out 3f388ce6 as feature/deploy...
Skipping Git submodules setup
$ echo "Runnig before_script"
Runnig before_script
$ apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make
bash: line 88: apk: command not found
ERROR: Job failed: exit status 1
工作通过 后,我得到了:
Running with gitlab-runner 11.11.1 (5a147c92)
on docker-auto-scale fa6cab46
Using Docker executor with image docker:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image sha256:bed64de70fa1f4d0b5a498791647c45d954cb0306ec2852dbcfb956f4ff3b0d6 for docker:dind ...
Waiting for services to be up and running...
Pulling docker image docker:latest ...
Using docker image sha256:af42f41a7d73a4a181843011f62cbdefa6d0f546bc7b50f71163750e0475a928 for docker:latest ...
Running on runner-fa6cab46-project-12561543-concurrent-0 via runner-fa6cab46-srm-1559293461-381b8d99...
Initialized empty Git repository in /builds/<my.name>/<my.app>/.git/
Fetching changes...
Created fresh repository.
From https://gitlab.com/<my.name>/<my.app>
* [new branch] develop -> origin/develop
* [new branch] feature/deploy -> origin/feature/deploy
* [new branch] master -> origin/master
Checking out 3f388ce6 as feature/deploy...
Skipping Git submodules setup
$ echo "Runnig before_script"
Runnig before_script
$ apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/30) Installing binutils (2.31.1-r2)
(2/30) Installing gmp (6.1.2-r1)
(3/30) Installing isl (0.18-r0)
...
...
...
答案 0 :(得分:1)
发生这种情况是因为您有不同的跑步者,“我的跑步者Jd5HNvxy”和“ docker-auto-scale fa6cab46”。您的工作正在由哪个运行速度更快的跑步者来执行。
在失败的情况下,您的工作在标记为“ shell executor”的运行程序上运行,在ubuntu系统上运行-在日志中可见。 Ubuntu没有附带apk命令,因此作业失败。
但是,您的其他运行程序使用“ docker”执行程序,因此可以拉取docker映像并运行该作业而不会出现问题。
可能的解决方案: