Do docker pull using jenkins Do docker pull using jenkins jenkins jenkins

Do docker pull using jenkins


These steps are executed programmatically by the plugin.Alternatively you can execute an script into a jenkins slave with docker installed in build->execute shell:

#!/bin/bashexport image=`docker images httpd|wc -l`echo image $imageif [ "$image" -lt "1" ];then    docker pull httpd fiexport container=`docker ps -all -f="name=webcontainer"|wc -l`echo container $containerif [ "$container" -gt "1" ];then    echo "Deleting webcontainer"    docker rm -f webcontainer fiBUILD_ID=dontKillMe docker run -d -t -p8888:80 --name webcontainer httpd

You can interact with created docker with below command:

`docker exec -it  webcontainer /bin/bash`


These days (mid 2017, more than a year after the OP's question), you would use an inside directive of a Jenkins pipeline to pull and run within a docker image some commands.

For instance (Using Jenkins Pipelines with Docker), using the Docker Pipeline plugin:

docker.image('ruby:2.3.1').inside {    stage("Install Bundler") {      sh "gem install bundler --no-rdoc --no-ri"    }    stage("Use Bundler to install dependencies") {      sh "bundle install"    }}