我有一个bitbucket管道,必须执行django unittests。因此,我需要一个测试数据库,它应该是一个SQL SERVER数据库。
管道是这样的。
# This is a sample build configuration for Python.
# Check our guides at https://confluence.atlassian.com/x/x4UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: python:3.7.3
pipelines:
branches:
master:
- step:
name: Setup sql
image: fabiang/sqlcmd
script:
- sqlcmd -S localhost -U sa -P $DB_PASSWORD
services:
- sqlserver
- step:
name: Run tests
caches:
- pip
script: # Modify the commands below to build your repository.
- python3 -m venv my_env
- source my_env/bin/activate
- apt-get update && apt-get install
- pip3 install -r req-dev.txt
- python3 manage.py test
- step:
name: Linter
script: # Modify the commands below to build your repository.
- pip3 install flake8
- flake8 --exclude=__init__.py migrations/
definitions:
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2017-latest
variables:
ACCEPT_EULA: Y
SA_PASSWORD: $DB_PASSWORD
每次当我运行管道的时候,我都会得到:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2726.
我试着在本地运行,但只有当我定义了一个端口时,它才会工作。-p
标签。docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong!' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest
我怎样才能让管道工作?(可能是定义一个端口,但如何定义?)
我想问题出在你调用脚本的时候。- sqlcmd -S localhost -U sa -P $DB_PASSWORD
因为你的sqlserver还没有完成初始化。
试着把一个 sleep 10
前,最好在命令前加上错误情况,如果命令失败了 sleep 5
并再次重试。