Jenkins Docker Sidecar with Container Running a daemon command

321 views
Skip to first unread message

Justin Seiser

unread,
Nov 20, 2018, 9:33:26 AM11/20/18
to Jenkins Users
I want to run ZAP as a proxy in my pipeline, and run my selenium tests through the proxy. Im just using curl in a container in place of selenium for my testing and was able to make this work locally using docker.

In my pipeline, zap starts up, but the pipeline just sits in the zap container after that, never progressing to the second container. I understand why, Ive launched a process as a daemon, its never going to finish, so the step never finished. I just dont understand how to accomplish what I need in jenkins.

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

I essentially need to start zap with the command im using in the 'inside', and only kill the container when the second containers steps are complete.

Björn Pedersen

unread,
Nov 21, 2018, 10:02:34 AM11/21/18
to Jenkins Users


Am Dienstag, 20. November 2018 15:33:26 UTC+1 schrieb Justin Seiser:
I want to run ZAP as a proxy in my pipeline, and run my selenium tests through the proxy. Im just using curl in a container in place of selenium for my testing and was able to make this work locally using docker.

In my pipeline, zap starts up, but the pipeline just sits in the zap container after that, never progressing to the second container. I understand why, Ive launched a process as a daemon, its never going to finish, so the step never finished. I just dont understand how to accomplish what I need in jenkins.

stage('Run Zap Proxy'){
        docker
.image('owasp/zap2docker-weekly').withRun('-p 8090:8090') { c ->
         
         withRun starts the container.  So you want to add your zap.sh call as command here.
  docker.image('owasp/zap2docker-weekly').inside("-v $WORKSPACE:/zap/wrk:rw") {
               
/* Wait until mysql service is up */

   here you start a second container, that  never stops...
 
                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
               """

           
}

   So you never arrive here.
 
Reply all
Reply to author
Forward
0 new messages