【问题标题】:Jenkins Docker Sidecar with Container Running a daemon command带有容器的 Jenkins Docker Sidecar 运行守护程序命令
【发布时间】:2019-04-22 23:42:32
【问题描述】:

我想在我的管道中将 ZAP 作为代理运行,并通过代理运行我的 selenium 测试。我只是在容器中使用 curl 代替 selenium 进行测试,并且能够使用 docker 在本地完成这项工作。

在我的管道中,zap 启动了,但此后管道仅位于 zap 容器中,从未进入第二个容器。我明白为什么,我作为守护进程启动了一个进程,它永远不会完成,所以这一步永远不会完成。我只是不明白如何在詹金斯中完成我所需要的。

stage('Run Zap Proxy'){
        docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090') { c ->
            docker.image('owasp/zap2docker-weekly').inside("-v $WORKSPACE:/zap/wrk:rw") {
                /* Wait until mysql service is up */
                sh """
                   zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true
               """
            }
            docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
                sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
                sh """
                   curl -k -x http://proxy:8090 \
                       -X POST https://my.fqdn.net/api/rest/sessions \
                       -H 'Content-Type: application/json' \
                       -H 'Accept: application/json' \
                       -d '{"username":"username","password":"password"}'
               """
                sh 'sleep 2m'
                sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
                stash includes: 'report.html', name: 'report'
            }
        }
}

我基本上需要使用 im 在“内部”中使用的命令启动 zap,并且只有在第二个容器阶段完成时才终止容器。

【问题讨论】:

    标签: docker jenkins zap


    【解决方案1】:

    您可以在withRun 部分直接传递zap 命令:

    stage('Run Zap Proxy'){
        docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090 -v $WORKSPACE:/zap/wrk:rw', 'zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true') { c ->
            docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
                sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
                sh """
                   curl -k -x http://proxy:8090 \
                       -X POST https://my.fqdn.net/api/rest/sessions \
                       -H 'Content-Type: application/json' \
                       -H 'Accept: application/json' \
                       -d '{"username":"username","password":"password"}'
               """
                sh 'sleep 2m'
                sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
                stash includes: 'report.html', name: 'report'
            }
        }
    }
    

    withRun 允许您覆盖 zap-container 的 CMD。检查这个API-documentation

    【讨论】:

      猜你喜欢
      • 2020-12-13
      • 1970-01-01
      • 2019-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-01
      相关资源
      最近更新 更多