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

标签 authentication jenkins jenkins-pipeline credentials gcloud

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

我也从文件中尝试过,但没有运气。
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 文件上传为 secret 文件 .
然后:

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}")
  }

关于authentication - 如何在 Jenkins 管道中使用 Google 服务帐户进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45355007/

相关文章:

python - 将 Python 脚本中的值列表返回到 Jenkins Pipeline

jenkins - 在步骤中未找到此类 DSL 方法 'publishHTML'

authentication - 与我自己的水疗中心一起使用时,OAuth2 资源所有者密码凭证授予是否安全?

android - 如何在移动应用程序中设置持久身份验证?

linux - 如何将凭证烘焙到 git 的 docker 镜像中?

ruby-on-rails - Rails 4,重定向到 "pages/congrats"

jenkins - 您可以在 Jenkins 构建计划中排除时间范围吗?

json - 从 JSON 字符串查询 secret 值(密码)

.net - Jenkins .Net和Docker?

jenkins - 有没有办法将Jenkins项目转换为Pipeline?