如何在Jenkins管道中使用Google服务帐户进行身份验证

ste*_*uck 7 authentication credentials jenkins gcloud jenkins-pipeline

我想gcloud在Jenkins管道中使用,因此必须首先使用Google Service帐户进行身份验证。我使用的是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}"
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过from档案,但是没有运气。

withCredentials([file(credentialsId:'my-creds', variable: 'GCSKEY')]) {
Run Code Online (Sandbox Code Playgroud)

日志显示:

org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException: Credentials 'my-creds' is of type 'Google Service Account from private key' ....
Run Code Online (Sandbox Code Playgroud)

Jul*_*ere 12

您需要将您的“服务帐户” 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}")
  }
Run Code Online (Sandbox Code Playgroud)

  • 为什么每次读到这里我都不能点赞?@stackoverflow请 (6认同)
  • 请**更大胆、更清晰** JSON 文件应作为秘密文件上传,而不是作为 Google 服务帐户上传 (4认同)