我想gcloud在Jenkins管道中使用,因此必须首先使用Google Service帐户进行身份验证。我正在使用https://wiki.jenkins.io/display/JENKINS/Google+OAuth+Plugin,其中包含我的私钥凭据。我一直坚持将凭据加载到管道中:
gcloud
withCredentials([[$class: 'MultiBinding', credentialsId: 'my-creds', variable: 'GCSKEY']]) { sh "gcloud auth activate-service-account --key-file=${GCSKEY}" }
我也尝试过from档案,但是没有运气。
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文件作为 机密文件 上传。然后:
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}") }