当前位置: 首页 > 面试题库 >

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

晋俊贤
2023-03-14
问题内容

我想gcloud在Jenkins管道中使用,因此必须首先使用Google
Service帐户进行身份验证。我正在使用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}"
}

我也尝试过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}")
  }


 类似资料:
  • 下面是示例代码:https://code.google.com/p/google-api-dotnet-client/wiki/oauth2#service_accounts 授权失败:dotnetOpenAuth.Messaging.ProtocolException:发送直接消息或获取响应时出错。 内部异常是System.net.WebException:远程服务器返回错误:(400)Bad

  • 我的团队目前正在开发一个应用程序,使用Admin SDK在GCP中列出公司的域用户,用于入职和非入职目的。 我们使用一个服务帐户来完成这个任务,并且在Google Admin's advanced settings中添加了 作用域。管理SDK API被激活,我们可以在凭据区域中看到服务帐户。 当我们使用参数 和 调用https://www.googleapis.com/admin/director

  • GoogleCredential凭证=newGoogleCredential.Builder(). setTransfer(TRANSPORT). setJsonFactory(JSON_FACTORY). setServiceAccount tId("SOMETHING@developer.gserviceaccount.com"). setServiceAccount tScopes(Bigq

  • 我正在努力解决这个问题:我正在尝试使用一个服务帐户,从PHP脚本在Google日历中创建一个事件。 以下是我所做的: 创建了一个Google Cloud Project 启用日历API 创建了一个OAuth 2.0服务帐户,其中包含客户端ID、电子邮件地址和公钥 下载了密钥文件并将其保存在我的网站中 使用服务帐户中创建的电子邮件地址共享我的日历(具有管理共享权限) 这是我的代码: 我已经尽可能地调

  • 问题内容: 我正在尝试使用oauth API通过Java API对Google服务帐户进行身份验证。我希望使用它来访问Google Bigquery。我的API请求返回了“无效的赠款”。 这是代码,它是基本身份验证示例的副本(不是Bigquery的。而是另一个Google API): SERVICE_ACCOUNT_EMAIL是以下格式的电子邮件地址:XXXXXXX@developer.gserv