【问题标题】:How to use nested docker.image('test_image').inside() in a Jenkins pipeline如何在 Jenkins 管道中使用嵌套的 docker.image('test_image').inside()
【发布时间】:2017-06-30 05:09:31
【问题描述】:

我有一个 jenkins 容器,它触发一个 maven 容器来构建一个 java 代码。 现在我想用 selenium 测试相同的代码。 我有另一个硒服务器容器。 但是使用 selenium 运行测试的命令是需要 Maven 的 mvn 命令。 由于我在 selenium 容器内执行此操作,因此无法识别 mvn。 如何在 selenium 容器内使用 maven 容器?可以嵌套吗? 我不想将所有东西都安装在同一个容器中。 这是 Jenkins 文件:

    node {
     stage('checkout') {
                git credentialsId: 'Gitlab_cred', url: 'urlhere'
         }

         stage('Build') {
                    docker.image('mvn_custom_image').inside('-u root'){
                      //mvn commands to build the project
                    }
          }

         stage('Archive and Packaging') {
            archiveArtifacts '**/*.war'
          }

         stage('Integration Test') {
            docker.image('selenium/node-firefox:3.4.0-dysprosium').inside{
                 //I want to run mvn command using selenium here
                // This image doesn't have mvn

            }
        }
     }

我可以在另一个容器中使用“docker.image('mvn_custom_image').inside”吗(在我的情况下是 selenium)?

或任何其他具有类似结果的方式。

【问题讨论】:

    标签: maven selenium docker jenkins-pipeline


    【解决方案1】:

    https://www.jenkins.io/doc/book/pipeline/docker/上有很好的例子

    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'
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-28
      • 1970-01-01
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      • 1970-01-01
      相关资源
      最近更新 更多