docker - 如何在Jenkins管道中设置postgres数据库?

标签 docker jenkins jenkins-pipeline

我正在使用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。

我的看法是:

  • 使用
  • 创建图像
  • 以某种方式将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/

    相关文章:

    ruby - 在 ruby​​ 程序中记录到 STDOUT(不适用于 Docker)

    Jenkins 管道: how can I disable the current job from inside a pipeline?

    jenkins - 如何将文件存储在jenkins的build文件夹中?

    bash - Jenkins:管道 sh 错误替换错误

    django - 如何在 Jenkins 多分支管道中添加环境变量

    Jenkins : Groovy : Scripts not permitted to use method groovy. lang.GroovyObject getProperty java.lang.String

    django/apache 无法在 Docker 容器中提供网页。错误 - ModuleNotFoundError : No module named 'django'

    docker - AWS上的Docker群负载平衡不起作用

    docker - 如何在我的 Mac 上查看在 Docker 中运行的所有 minikube 集群的列表?

    jenkins - 从 Jenkinsfile 中的共享库导入类