【问题标题】:How to authenticate with a Google Service Account in Jenkins pipeline如何在 Jenkins 管道中使用 Google 服务帐户进行身份验证
【发布时间】:2018-01-03 10:22:24
【问题描述】:

我想在 Jenkins 管道中使用 gcloud,因此我必须首先使用 Google 服务帐户进行身份验证。我正在使用 https://wiki.jenkins.io/display/JENKINS/Google+OAuth+Plugin 来保存我的私钥凭据。我坚持将凭据加载到管道中:

withCredentials([[$class: 'MultiBinding', credentialsId: 'my-creds', variable: 'GCSKEY']]) {
    sh "gcloud auth activate-service-account --key-file=${GCSKEY}"
}

我也从文件中尝试过,但没有运气。

withCredentials([file(credentialsId:'my-creds', variable: 'GCSKEY')]) {

日志说:

org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException: Credentials 'my-creds' is of type 'Google Service Account from private key' ....

【问题讨论】:

    标签: authentication jenkins jenkins-pipeline credentials gcloud


    【解决方案1】:

    我无法让“来自私钥的 Google 服务帐户”正常工作,但在 Jenkins 中使用“秘密文件”类型的凭据,并上传了我的 Google 服务帐户 JSON 工作。

    【讨论】:

      【解决方案2】:

      您需要将您的服务帐户 JSON 文件作为秘密文件上传。 那么:

      withCredentials([file(credentialsId: 'key-sa', variable: 'GC_KEY')]) {
          sh("gcloud auth activate-service-account --key-file=${GC_KEY}")
          sh("gcloud container clusters get-credentials prod --zone northamerica-northeast1-a --project ${project}")
        }
      

      【讨论】:

      • 为什么我每次读到这里都不能投票? @stackoverflow plz
      • 更大胆更清楚 JSON 文件应作为机密文件而不是 Google 服务帐户上传
      • 它也适用于我,但我应该使用。 '${GC_KEY}' .
      • 我得到了这个:错误:(gcloud.auth.activate-service-account)刷新您当前的身份验证令牌时出现问题:('invalid_grant:无效的JWT:令牌必须是短期令牌(60 分钟)并在合理的时间范围内。检查 JWT 声明中的 iat 和 exp 值。',
      猜你喜欢
      • 1970-01-01
      • 2020-05-21
      • 2013-09-23
      • 2017-11-03
      • 2016-01-31
      • 2015-03-13
      • 1970-01-01
      • 1970-01-01
      • 2018-11-25
      相关资源
      最近更新 更多