use gcloud with Jenkins

后端 未结 1 432
名媛妹妹
名媛妹妹 2021-02-08 21:58

I\'ve been trying to write a script that polls Google Cloud Storage periodically. This works fine when I run it normally, but if I include it as a build step in Jenkins, it give

相关标签:
1条回答
  • 2021-02-08 22:42

    Your best bet is probably to use a "service account" to authenticate gcloud/gsutil with the GCS service. The major steps are to use generate a JSON-formated private key following the instructions here:

    https://cloud.google.com/storage/docs/authentication#service_accounts
    

    Copy that key to a place where the Jenkins user can read it, and as the Jenkins user run

    gcloud auth activate-service-account ...
    

    (See https://cloud.google.com/storage/docs/authentication#service_accounts). Note that support for JSON key files is pretty new and you'll need an up-to-date gcloud release.

    From there your Jenkins process should be able to access GCS as usual.

    The key file should have the following format:

    {
      "private_key_id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "private_key": "-----BEGIN PRIVATE KEY-----\n ...  \n-----END PRIVATE KEY-----\n",
      "client_email": "...@developer.gserviceaccount.com",
      "client_id": "..."
      "type": "service_account"
    }
    
    0 讨论(0)
提交回复
热议问题