Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins always pull docker image from a declarative pipeline agent definition

I have a working Jenkins pipeline defined with agent {any}.

But I want to try running the tests on a docker image. According to documentation I can do that the following way:

pipeline {
     agent {
         docker { image 'centos/python-27-centos7:latest' }
     }
     stages {
        ...
     }
}

The problem is that my instance of Jenkins is offline and with this configuration it will try to docker pull the image when running the project.

However I have the centos/python-27 image loaded in the docker (visible with docker images and it can be run with docker run -i -t centos/python-27-centos7 /bin/bash

Is there any way I can configure the agent in Jenkins so it doesn't try to pull the image from Docker Hub?

like image 656
LaintalAy Avatar asked Sep 20 '17 16:09

LaintalAy


People also ask

What is Docker agent in Jenkins?

It is a Jenkins Cloud plugin for Docker. The aim of this docker plugin is to be able to use a Docker host to dynamically provision a docker container as a Jenkins agent node, let that run a single build, then tear-down that node, without the build process (or Jenkins job definition) requiring any awareness of docker.

What is agent in Jenkins pipeline?

Agent. An agent is typically a machine, or container, which connects to a Jenkins controller and executes tasks when directed by the controller. Artifact. An immutable file generated during a Build or Pipeline run which is archived onto the Jenkins Controller for later retrieval by users.

What is declarative pipeline in Jenkins?

Pipeline adds a powerful set of automation tools onto Jenkins, supporting use cases that span from simple continuous integration to comprehensive continuous delivery pipelines. The steps to build, test, and deliver each application become part of the application itself, stored in a Jenkinsfile.


1 Answers

The Docker agent has an alwaysPull flag you can set to false or true:

agent {
  docker {
    alwaysPull false
    image 'foo/bar'
  }
}

Jenkins has a Pipeline Syntax Generator that can help in these cases. In the Job menu on the left side, there is an icon for "Pipeline Syntax".

enter image description here

There you can see some settings to help you generate your pipeline directives.

enter image description here

like image 117
Gus Avatar answered Oct 22 '22 20:10

Gus