如何使用Jenkins声明性语法登录Docker? [英] How to login to docker in Jenkins declarative syntax?
本文介绍了如何使用Jenkins声明性语法登录Docker?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的目标是使用声明性语法从DockerHub上的私有存储库中拉取/推送图像.
My objective is to pull/push images from private repositories on DockerHub using declarative syntax.
我已将我的凭据配置为ID xxxxxxxxxxx
.我了解我可以使用程序化语法如此处所示来做到这一点 ,但是如何以声明方式进行操作,以便保持对CI流程的有用概述?
I've configured my credentials with id xxxxxxxxxxx
. I understand I can do this with the programmatic syntax as shown here, but how can I do it in declarative so I maintain the useful overview of the CI process?
推荐答案
您可以将script {}
块用作声明性步骤,以包装仅在脚本管道中运行的所有内容.例如(未试用)
You can use a script {}
block as a declarative step to wrap anything that would otherwise only run in scripted pipelines. e.g. (untested)
stages {
stage('Example') {
steps {
script {
docker.withRegistry('https://registry.example.com', 'credentials-id') {
def customImage = docker.build("my-image:${env.BUILD_ID}")
/* Push the container to the custom Registry */
customImage.push()
}
}
}
}
}
这篇关于如何使用Jenkins声明性语法登录Docker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文