2017-04-10 69 views
1

我试图通过测试项目https://gitlab.com/khpeek/CI-test来熟悉Gitlab CI环境。该项目具有以下.gitlab-ci.yml使用GitLab CI和Python'onbuild'图像,requirements.txt中的包似乎没有安装

image: python:2.7-onbuild 
services: 
    - rethinkdb:latest 
test_job: 
    script: 
    - pytest 

的问题是,在CI管道test_job作业失败,出现以下错误信息:

Running with gitlab-ci-multi-runner 9.0.1 (a3da309) 
    on docker-auto-scale (e11ae361) 
Using Docker executor with image python:2.7-onbuild ... 
Starting service rethinkdb:latest ... 
Pulling docker image rethinkdb:latest ... 
Using docker image rethinkdb:latest ID=sha256:23ecfb08823bc5483c6a955b077a9bc82899a0df2f33899b64992345256f22dd for service rethinkdb... 
Waiting for services to be up and running... 
Using docker image sha256:aaecf574604a31dd49a9d4151b11739837e4469df1cf7b558787048ce4ba81aa ID=sha256:aaecf574604a31dd49a9d4151b11739837e4469df1cf7b558787048ce4ba81aa for predefined container... 
Pulling docker image python:2.7-onbuild ... 
Using docker image python:2.7-onbuild ID=sha256:5754a7fac135b9cae7e02e34cc7ba941f03a33fb00cf31f12fbb71b8d389ece2 for build container... 
Running on runner-e11ae361-project-3083420-concurrent-0 via runner-e11ae361-machine-1491819341-82630004-digital-ocean-2gb... 
Cloning repository... 
Cloning into '/builds/khpeek/CI-test'... 
Checking out d0937f33 as master... 
Skipping Git submodules setup 
$ pytest 
/bin/bash: line 56: pytest: command not found 
ERROR: Job failed: exit code 1 

然而,与存储库中requirements.txt其中单行pytest==3.0.7。在我看来,python:2.7-onbuild图片的Dockerfile,然而,pip install -r requirements.txt应该在生成上运行。那么为什么pytest找不到?

回答

1

如果你看看你链接到的Dockerfile,你会看到pip install -r requirements.txtonbuild命令的一部分。如果您想从第一个容器创建一个新容器并安装一堆需求,这非常有用。因此,pip install -r requirements.txt命令不会在CI管道中的容器中执行,如果是,它将在一开始就执行,即使在克隆gitlab存储库之前也是如此。

我建议您修改.gitlab-ci.yml文件这样

image: python:2.7-onbuild 
services: 
    - rethinkdb:latest 
test_job: 
    script: 
    - pip install -r requirements.txt 
    - pytest 
0

这个问题似乎是间歇性:虽然第一次花了61分钟运行测试(最初失败),现在大约需要一分钟(见下面的屏幕截图)。

作为参考,测试存储库位于https://gitlab.com/khpeek/CI-test。 (我必须添加一个before_script以及一些pip install才能使工作成功)。

enter image description here