如何使用 Jenkins 声明性语法登录 docker?

2024-06-19

我的目标是使用声明性语法从 DockerHub 上的私有存储库中拉取/推送图像。

我已经用 id 配置了我的凭据xxxxxxxxxxx。我知道我可以使用编程语法来做到这一点如图所示 https://jenkins.io/doc/book/pipeline/docker/#custom-registry, but 我如何以声明式方式完成此操作,以便保持 CI 流程的有用概述?


您可以使用script {}块作为声明性步骤来包装任何只能在脚本化管道中运行的内容。例如(未经测试)

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()
                }
            }
        }
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Jenkins 声明性语法登录 docker? 的相关文章

随机推荐