Using a docker image in a declarative pipeline

49 views
Skip to first unread message

Guy Knights

unread,
May 5, 2017, 4:36:41 PM5/5/17
to jenkins...@googlegroups.com
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

Matt Stave

unread,
May 18, 2017, 9:06:40 AM5/18/17
to Jenkins Users
I think script {} is the answer...
Reply all
Reply to author
Forward
0 new messages