Jenkins 中的 Docker 推送 - 被拒绝:请求访问资源被拒绝

shr*_*mpy 3 jenkins docker jenkins-pipeline

所以我试图在 Jenkins 中建立一个管道来构建镜像并将它们推送到 Docker 集线器。我在 Manage 'Jenkins' 中的凭据与“docker-hub-credentials”相同,并且似乎已被使用。

它可以构建,但它只是无法通过推送...帮助?我已经做了几个小时了,我不确定我错过了什么。

我已经尝试过使用 docker login,但是 jenkins 不允许。

stage('Build image') {
    /* This builds the actual image; synonymous to
     * docker build on the command line */

     bat 'docker build -t username/foldername:build . '    }


stage('Push image') {
    /* Finally, we'll push the image with two tags:
    docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') {
        bat 'docker push username/foldername:build'
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望图像被推送,但我有这个:

The push refers to repository [docker.io/username/foldername]
a73d7d9f4346: Preparing
964bdfb24a54: Preparing
1af124d739c9: Preparing
6cffeea81e5d: Preparing
614a79865f6d: Preparing
612d27bb923f: Preparing
ef68f6734aa4: Preparing
612d27bb923f: Waiting
ef68f6734aa4: Waiting
denied: requested access to the resource is denied
Run Code Online (Sandbox Code Playgroud)

shr*_*mpy 5

我找到了答案!!!

 stage('Push image') {
        withDockerRegistry([ credentialsId: "docker-hub-credentials", url: "" ]) {
        bat "docker push devopsglobalmedia/teamcitydocker:build"
        }
Run Code Online (Sandbox Code Playgroud)