我想用gcloud
在 Jenkins 管道中,因此我必须首先使用 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' ....
最佳答案
您需要将您的服务帐户 JSON 文件上传为 secret 文件 .
然后:
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}")
}
关于authentication - 如何在 Jenkins 管道中使用 Google 服务帐户进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45355007/