【问题标题】:Pushing docker image through jenkins通过 jenkins 推送 docker 镜像
【发布时间】:2019-02-07 12:11:07
【问题描述】:

我正在通过 Jenkins 管道推送 docker 映像,但出现以下错误:

错误:找不到匹配的凭据 gcr:["google-container-registry"]

我试过了:

gcr:["google-container-registry"]
gcr:[google-container-registry]
gcr:google-container-registry
google-container-registry

但它们都不起作用。

在我拥有的全局凭据中:

名称:google-container-registry

种类:来自私钥的 Google 服务帐户

描述:用于访问 Google API 和 服务。

【问题讨论】:

  • 您是否拥有具有存储管理员权限的关联服务帐户密钥?
  • Jenkins 代理是否使用该凭据文件?
  • 是的,我在 json 中有一个服务帐户密钥。我在 Jenking 中将其作为 google 服务帐户导入。

标签: google-cloud-platform jenkins-pipeline


【解决方案1】:

正确的语法如下(假设您的 gcr 凭据 ID 是“google-container-registry”):

docker.withRegistry("https://gcr.io", "gcr:google-container-registry") {
  sh "docker push [your_image]"
}

【讨论】:

    【解决方案2】:

    检查您是否安装了https://plugins.jenkins.io/google-container-registry-auth/ 插件。

    插件安装后使用gcr:credential-id synthax

    例子:

    stage("docker build"){
        Img = docker.build(
            "gcpProjectId/imageName:imageTag",
            "-f Dockerfile ."
        )
    }
    
    stage("docker push") {
        docker.withRegistry('https://gcr.io', "gcr:credential-id") {
            Img.push("imageTag")
        }
    }
    

    【讨论】:

      【解决方案3】:

      转到 Jenkins → 管理 Jenkins → 管理插件并安装插件: 谷歌容器注册 Google OAuth 凭据 CloudBees Docker 构建和发布

      Jenkins → Credentials → Global Credentials → Add Credentials,选择所需的“项目名称”并上传 JSON 文件

      Jenkins 文件:

       stage('Deploy Image') {
                      steps{
                          script {
                              docker.withRegistry( 'https://gcr.io', "gcr:${ID}" ) {
                                  dockerImage.push("$BUILD_NUMBER")
                                  dockerImage.push('latest')
                              }
                          }
                      }
                  }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-13
        • 1970-01-01
        • 2019-02-28
        • 1970-01-01
        • 2020-01-30
        • 2020-10-28
        • 2020-05-09
        • 1970-01-01
        相关资源
        最近更新 更多