如何在 Jenkins 管道中使用 Google 服务帐户进行身份验证 [英] How to authenticate with a Google Service Account in Jenkins pipeline
本文介绍了如何在 Jenkins 管道中使用 Google 服务帐户进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 Jenkins 管道中使用 gcloud
,因此我必须首先使用 Google 服务帐户进行身份验证.我正在使用 https://wiki.jenkins.io/display/JENKINS/包含我的私钥凭据的 Google+OAuth+Plugin.我坚持将凭据加载到管道中:
I want to use gcloud
in Jenkins pipeline and therefore I have to authenticate first with the Google Service account. I'm using the https://wiki.jenkins.io/display/JENKINS/Google+OAuth+Plugin which holds my Private Key Credentials. 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')]) {
日志说:
org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException: Credentials 'my-creds' is of type 'Google Service Account from private key' ....
推荐答案
您需要将您的服务帐户 JSON 文件上传为 秘密文件.那么:
You need to upload your Sevice Account JSON file as a secret file. 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}")
}
这篇关于如何在 Jenkins 管道中使用 Google 服务帐户进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文