python - 如何在 gitlab (CI/CD) 上使用 python 和 mongodb
问题描述
我在 gitlab 上使用 CI/CD 时遇到问题。我总是使用“python:latest”,但它是 2.7.5 版本,但我想使用 python2.7.15 或 python3.7。我该如何安装它?
-
image: python:latest
services:
- mongo:latest
variables:
MONGO_DB: ipc_alert
cache:
paths:
- ~/.cache/pip/
before_script:
- python -V
- pip install -r req.txt
stages:
- test
test:
stage: test
script:
- echo 'Testing'
解决方案
On the image you're posting, you have a different problem. You cannot find django on a valid version for your requirements.
About the question itself, if you want to test against multiple versions, you need to create more than one test. For example:
test:
stage: test
script:
- echo 'Testing'
That's will be:
test-python2.7:
stage: test
image: python:2.7
script:
- echo 'Testing'
test-python3.4:
stage: test
image: python:3.4
script:
- echo 'Testing'
test-python3.5:
stage: test
image: python:3.5
script:
- echo 'Testing'
test-python3.6:
stage: test
image: python:3.6
script:
- echo 'Testing'
test-python3.7:
stage: test
image: python:3.7
script:
- echo 'Testing'
test-python.latest:
stage: test
image: python:latest
script:
- echo 'Testing'
However, maybe this doesn't work, because you're using a "Shell executor". If I remember correctly, this runner execute your code against the current machine. You need to install docker and create a new runner who uses these docker. Without it, you cannot test against different environments / versions.
One exception to this, are if you have all python versions you need installed on your machine, and calls each python concrete version. It depends on your environment, but you can check on /usr/bin if you have multiple python versions. On my machine, I have on /usr/bin these ones:
maqui@kanade:~$ python -V
Python 2.7.15+
maqui@kanade:~$ python2.6 -V
Python 2.6.8
maqui@kanade:~$ python2.7 -V
Python 2.7.15+
maqui@kanade:~$ python3.6 -V
Python 3.6.8rc1
maqui@kanade:~$ python3.7 -V
Python 3.7.2rc1
(As you can see, python is an alias for python2.7).
推荐阅读
- javascript - 为什么这个函数立即执行
- java - 使用类元数据序列化 JSON
- python - 通用详细视图视图必须使用 URLconf 中的对象 pk 或 slug 调用
- jsf - Tomahawk JSF 1.2 文件上传在 JBoss 7.3 EAP 中不起作用,而在 JBoss 6 中运行良好
- python - 每隔一天为 Google OR 工具“员工计划”添加约束
- device - 在医疗设备中使用 Google Fit API
- java - 带有播放框架 2.6.x 的 Java WS 上的未确定错误
- java - 无法在 keycloak 上查看登录页面
- pandas - 在数据框中解析字典
- ios - 比较 Swift 中自定义类的属性