1

I would like to do next steps using jenkins:

1- docker pull <image_name>
2- docker run -i -t <command>

I´ve installed docker plugin on jenkins but is it this prossible? The documentations in docker plugin page is very poor .

Juan Reina Pascual
  • 3,988
  • 7
  • 21
  • 34
  • Docker appears in the 'Cloud' section of the Jenkins configuration, select "Docker" from the "Add a new cloud" drop down menu. Click the Add button to add a new image. Next on Build of a job step you can use it. – Valeriy Solovyov Apr 27 '16 at 19:22

2 Answers2

1

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/bash
export image=`docker images httpd|wc -l`
echo image $image
if [ "$image" -lt "1" ];
then
    docker pull httpd 
fi
export container=`docker ps -all -f="name=webcontainer"|wc -l`
echo container $container
if [ "$container" -gt "1" ];
then
    echo "Deleting webcontainer"
    docker rm -f webcontainer 
fi
BUILD_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`
Rubén Pozo
  • 1,035
  • 1
  • 12
  • 23
1

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"
    }
}
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250