[英]How to authenticate with a Google Service Account in Jenkins pipeline
I want to use gcloud
in Jenkins pipeline and therefore I have to authenticate first with the Google Service account. 我想在Jenkins管道中使用gcloud
,因此我必须首先使用Google服务帐户进行身份验证。 I'm using the https://wiki.jenkins.io/display/JENKINS/Google+OAuth+Plugin which holds my Private Key Credentials. 我正在使用https://wiki.jenkins.io/display/JENKINS/Google+OAuth+Plugin来保存我的私钥凭证。 I'm stuck with loading the credentials into the pipeline: 我坚持将凭据加载到管道中:
withCredentials([[$class: 'MultiBinding', credentialsId: 'my-creds', variable: 'GCSKEY']]) {
sh "gcloud auth activate-service-account --key-file=${GCSKEY}"
}
I also tried it with from file, but without luck. 我也从文件中尝试过,但没有运气。
withCredentials([file(credentialsId:'my-creds', variable: 'GCSKEY')]) {
The log says: 日志说:
org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException: Credentials 'my-creds' is of type 'Google Service Account from private key' ....
You need to upload your Sevice Account JSON file as a secret file . 您需要将您的服务帐户JSON文件上传为机密文件 。 Then: 然后:
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}")
}
我无法使用“私钥中的Google服务帐户”工作,但在Jenkins中使用“秘密文件”类型的凭据,并上传了我的Google服务帐户JSON。
The attached image is self-explanatory! 附图是不言自明的! Let me know if you don't understand it! 如果您不理解,请告诉我! Btw, you've to install the above mentioned plugin (which i assume You have done) and navigate to Jenkins>Configure Global Security and you can find these options there. 顺便说一句,你要安装上面提到的插件(我假设你已经完成)并导航到Jenkins>配置全局安全性,你可以在那里找到这些选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.