Jenkins/Docker: How to force pull base image before build

Viewed 12073

Docker allows passing the --pull flag to docker build, e.g. docker build --pull -t myimage .. How can I enforce pulling the base image with a pipeline script in my Jenkinsfile? This way I want to ensure that the build always uses the latest container image despite of the version available locally.

node('docker') {
    def app

    stage('Checkout') {
        checkout scm
    }

    stage('Build image') {
        docker.withRegistry('https://myregistry.company.com', 'dcr-jenkins') {
            app = docker.build "myimage"
        }
    }

    stage('Publish image') {
        docker.withRegistry('https://myregistry.company.com', 'dcr-jenkins') {
            app.push("latest")
        }
    }
}
3 Answers
Related