Using a docker image in a declarative pipeline

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using a docker image in a declarative pipeline

Guy Knights
I've been playing around with the declarative pipeline syntax and I'm having trouble running a docker container to do some processing. To clarify, I *don't* want to run my entire pipeline in the container, I just need to run a container to do some processing as part of the pipeline.

I've had this working in a scripted pipeline like so:

def webpack_builder = docker.image('webpack:latest').run("-v \"${WORKSPACE}/gtp:/opt/gtp\" -v \"/opt/gtp-images/${IMAGES_PATH}:/opt/gtp/app/images\" -e \"GTP_DIR=/opt/gtp\" -e \"DO_BUILD=true\" -e \"CONFIG=webpack.config.js\" -e \"ENVIRONMENT=production\"")

def cid = webpack_builder.id

sh """
      set +x
      docker logs -f ${cid}
      if [ "\$(docker ps -a|sed -ne 's/^.*Exited.*(\\([0-9]*\\)).*\$/\\1/p')" -eq 0 ]; then
         docker stop ${cid} && docker rm ${cid}
      else
         echo "Webpack build failed"
         docker stop ${cid}
         exit 1
      fi
"""

However I tried transplanting this directly to the declarative pipeline and it doesn't seem to work. I believe I could add it as a script { } block, but this seems kludgy to me. Is there a way to transpose this to a syntax that would work in a declarative pipeline? I found the docs not very informative on this issue.

Thanks,
Guy

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CANNH9mvFgvk9C%2BXSJ2Q0mDxxvOYvkwi6j6i726Y0aHJAZ4%2B88Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Using a docker image in a declarative pipeline

Matt Stave
I think script {} is the answer...

On Friday, May 5, 2017 at 3:36:41 PM UTC-5, Guy Knights wrote:
I've been playing around with the declarative pipeline syntax and I'm having trouble running a docker container to do some processing. To clarify, I *don't* want to run my entire pipeline in the container, I just need to run a container to do some processing as part of the pipeline.

I've had this working in a scripted pipeline like so:

def webpack_builder = docker.image('webpack:latest').run("-v \"${WORKSPACE}/gtp:/opt/gtp\" -v \"/opt/gtp-images/${IMAGES_PATH}:/opt/gtp/app/images\" -e \"GTP_DIR=/opt/gtp\" -e \"DO_BUILD=true\" -e \"CONFIG=webpack.config.js\" -e \"ENVIRONMENT=production\"")

def cid = <a href="http://webpack_builder.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwebpack_builder.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEk5lp2DQ4HpHlNw9wu_oaFu9MgJA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwebpack_builder.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEk5lp2DQ4HpHlNw9wu_oaFu9MgJA&#39;;return true;">webpack_builder.id

sh """
      set +x
      docker logs -f ${cid}
      if [ "\$(docker ps -a|sed -ne 's/^.*Exited.*(\\([0-9]*\\)).*\$/\\1/p')" -eq 0 ]; then
         docker stop ${cid} && docker rm ${cid}
      else
         echo "Webpack build failed"
         docker stop ${cid}
         exit 1
      fi
"""

However I tried transplanting this directly to the declarative pipeline and it doesn't seem to work. I believe I could add it as a script { } block, but this seems kludgy to me. Is there a way to transpose this to a syntax that would work in a declarative pipeline? I found the docs not very informative on this issue.

Thanks,
Guy

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/bb5ba064-a2ff-444d-8c72-05e2c1f75e7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.