我正在使用docker为我的应用程序模拟postgres数据库。我在 Cypress (Cypress)上进行了一段时间的测试,效果很好。我想设置Jenkins进行进一步的测试,但我似乎陷入了困境。
在我的设备上,我将使用命令docker create -e POSTGRES_DB=myDB -p 127.0.0.1:5432:5432 --name myDB postgres
docker start myDB
创建它。如何在Jenkins管道中对此进行模拟?我需要该应用程序的数据库才能正常工作。
我使用Dockerfile作为代理,并且尝试将ENV变量放在其中,但是它不起作用。尚未在管道上安装Docker。
我的看法是:
最佳答案
这可能是Jenkins Pipeline's advanced features边车模式之一的用例。
例如(来自上述站点):
node { checkout scm docker.image('mysql:5').withRun('-e "MYSQL_ROOT_PASSWORD=my-secret-pw"') { c -> docker.image('mysql:5').inside("--link ${c.id}:db") { /* Wait until mysql service is up */ sh 'while ! mysqladmin ping -hdb --silent; do sleep 1; done' } docker.image('centos:7').inside("--link ${c.id}:db") { /* * Run some tests which require MySQL, and assume that it is * available on the host name `db` */ sh 'make check' } } }
The above example uses the object exposed by withRun, which has the running container’s ID available via the id property. Using the container’s ID, the Pipeline can create a link by passing custom Docker arguments to the inside() method.
最好的事情是,工作完成后应自动停止并移除容器。
关于docker - 如何在Jenkins管道中设置postgres数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54091383/