Jenkins / Docker:如何在构build之前强制拉取基础图像

Docker允许将--pull标志传递给--pull docker build ,例如docker build --pull -t myimage . 。 我怎样才能强制在我的Jenkinsfile使用pipe道脚本来拉取基础图像? 这样,我想确保构build始终使用最新的容器映像,尽pipe本地可用的版本。

 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") } } } 

docker rmi <image>docker build --pull之前的脚本开始docker build --pulldocker build --pull执行时,镜像不会在本地存在,所以每次都会下载新的docker build --pull

additionalBuildArgs完成这项工作。

例:

 pipeline { agent { label "docker" } stages { […] stage('Build image') { agent { dockerfile { reuseNode true registryUrl "https://registry.comapny.com" registryCredentialsId "dcr-jenkins" additionalBuildArgs "--pull --build-arg APP_VERSION=${params.APP_VERSION}" dir "installation/app" } } steps { script { docker { app = docker.build "company/app" } } } } […] } }