简体   繁体   中英

How to run this command gcloud auth application-default login inside bitbucket pipelines?

As I am running my unit test through bitbucket pipelines, the below error occurs in some of the tests

Uncaught Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
      at GoogleAuth.getApplicationDefaultAsync (node_modules/google-auth-library/build/src/auth/googleauth.js:183:19)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)
      at GoogleAuth.getClient (node_modules/google-auth-library/build/src/auth/googleauth.js:565:17)
      at GrpcClient._getCredentials (node_modules/google-gax/src/grpc.ts:202:20)
      at GrpcClient.createStub (node_modules/google-gax/src/grpc.ts:404:19)

Please check this for more details Error: Could not load the default credentials in the bitbucket pipelines while using google cloud logging

However, I would like to try this solution https://stackoverflow.com/a/42059661 , but I think this could only work if you're doing it manually since you have to choose an email to login with.

I would like to know how to run this command or an alternative command in the bitbucket pipeline that may solve my problem.

Please let me know if you have any other suggestions. Thank you in advance

From the documentation on deploy to Google Cloud

1.Create a Google service account key. For more guidance see Google's guide to creating service keys .

2.Once you have your key file, open up a terminal and browse to the location of your key file.

3.Encode your file in base64 format: base64 -w 0 and copy the output of the command.

Note: for some versions of MacOS the -w 0 is not necessary.

4.In your repo go to Repository settings, under Pipelines, select Repository variables and create a new variable named KEY_FILE and paste the encoded service account credentials.

5.Configure the pipe and add the variables: PROJECT and KEY_FILE

Activate the service account as follows

gcloud auth activate-service-account --key-file gcloud-api-key.json
Activated service account credentials for: [service-account-name@project-id.iam.gserviceaccount.com]
echo "$(gcloud auth list)"
To set the active account, run: $ gcloud config set account ACCOUNT
ACTIVE ACCOUNT
service-account-name@project-id.iam.gserviceaccount.com

Additionally you may have a look this stackoverflow link1 & link2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM