简体   繁体   English

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

[英]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.

相关问题 如何验证谷歌服务帐户凭据 - How to authenticate google service account credentials 如何使用不同的服务帐户凭据验证google API? - How to authenticate google APIs with different service account credentials? 如何通过网络应用程序对Google帐户服务进行身份验证以使用Google数据 - how to authenticate into google account service from web application for using google data 如何使用服务帐户和 bigrquery 包进行身份验证? - How to authenticate with service account and bigrquery package? Google 翻译 API V3:如何从文件流中验证服务帐户 - Google translate API V3: How to authenticate service account from file stream 如何在不下载服务帐户凭据的情况下从 Google Compute Engine 和本地验证 Google API(Google Drive API)? - How to authenticate Google APIs (Google Drive API) from Google Compute Engine and locally without downloading Service Account credentials? 使用php验证Google帐户 - Authenticate Google Account with php Sharepoint ODATA API以及如何使用服务帐户进行身份验证 - Sharepoint ODATA API & how to authenticate using service account 如何使用Google帐户在我们的网站上验证我们的用户 - How to authenticate our users in our website with Google Account 如何使用Google Gmail帐户(如stackoverflow)对用户进行身份验证 - How to authenticate a user with Google gmail account like stackoverflow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM