[英]In gitlab ci pipeline, how can I connect to redis service using python?
[英]How do I connect to redis from Python in a gitlab pipeline?
按照以下说明操作: https : //docs.gitlab.com/ce/ci/services/redis.html我已添加
services:
- redis:latest
到我的.gitlab-ci.yml
文件,并更改为redis connect call to:
redis.StrictRedis(host='redis', port=6379, db=0)
我得到的错误是:
/usr/local/lib/python2.7/site-packages/redis/client.py:772: in execute_command
connection = pool.get_connection(command_name, **options)
/usr/local/lib/python2.7/site-packages/redis/connection.py:994: in get_connection
connection.connect()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = Connection<host=redis,port=6379,db=0>
def connect(self):
"Connects to the Redis server if not already connected"
if self._sock:
return
try:
sock = self._connect()
except socket.timeout:
raise TimeoutError("Timeout connecting to server")
except socket.error:
e = sys.exc_info()[1]
> raise ConnectionError(self._error_message(e))
E ConnectionError: Error -2 connecting to redis:6379. Name or service not known.
事实证明,将服务声明放在每个任务中都很简单,例如:
py27:
stage: run
image: python:2.7
script:
- mkdir -p build/coverage
- pip install -r requirements.txt
- pytest --color=no --verbose --ignore=almanac/migrations --cov=almanac --cov-config=.coveragerc tests
- cp .coverage build/coverage/py27.coverage
services: # <===== here ========
- redis:latest
artifacts:
paths:
- build/coverage/*.coverage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.