I am trying to deploy a cloud function in GCP using CI-CD
process. I have written a yaml file. Below is my code:
cloudbuild.yaml
# Deploy Cloud Function
- name: "gcr.io/cloud-builders/gcloud"
id: deploy
dir: "/workspace/API/audit_from_storage"
args:
[
'gcloud', 'functions', 'deploy', 'audit_deployed',
'--set-env-vars', 'BASEURL=${_CP_BASE_URL},BUCKETNAME=${_BUCKETNAME},FUNCTION=${_FUNCTION}',
'--region=us-central1',
'--source=.',
'--trigger-resource=${_BUCKETNAME}',
'--trigger-event=google.storage.object.finalize',
'--runtime=nodejs10',
'--entry-point=collectAudit',
'--service-account=${_SERVICE_ACCOUNT}',
]
Below are the logs:
Finished Step #0 - "installing_npm"
Starting Step #1 - "deploy"
Step #1 - "deploy": Already have image (with digest): gcr.io/cloud-builders/gcloud
Step #1 - "deploy": ERROR: (gcloud) Invalid choice: 'gcloud'.
Step #1 - "deploy": Maybe you meant:
Step #1 - "deploy": gcloud functions deploy
Step #1 - "deploy": gcloud run deploy
Step #1 - "deploy": gcloud deployment-manager deployments cancel-preview
Step #1 - "deploy": gcloud deployment-manager deployments create
Step #1 - "deploy": gcloud deployment-manager deployments delete
Step #1 - "deploy": gcloud deployment-manager deployments describe
Step #1 - "deploy": gcloud deployment-manager deployments list
Step #1 - "deploy": gcloud deployment-manager deployments stop
Step #1 - "deploy": gcloud deployment-manager deployments update
Step #1 - "deploy":
Step #1 - "deploy": To search the help text of gcloud commands, run:
Step #1 - "deploy": gcloud help -- SEARCH_TERMS
Finished Step #1 - "deploy"
ERROR
ERROR: build step 1 "gcr.io/cloud-builders/gcloud" failed: step exited with non-zero status: 2
Please help me resolve this.
Below is the script after removing the gcloud
argument from the array list:
Edit:
# Deploy Cloud Function
- name: "gcr.io/cloud-builders/gcloud"
id: deploy
dir: "/workspace/API/audit_from_storage"
args:
[
'functions', 'deploy', 'audit_from_storage',
'--set-env-vars', 'BASEURL=${_CP_BASE_URL},BUCKETNAME=${_BUCKETNAME},FUNCTION=${_FUNCTION}',
'--region=us-central1',
'--source=.',
'--trigger-resource=${_BUCKETNAME}',
'--trigger-event=google.storage.object.archive',
'--runtime=nodejs10',
'--entry-point=collectAudit',
'--service-account=${_SERVICE_ACCOUNT}',
]
Below are the logs:
Starting Step #1 - "deploy"
Step #1 - "deploy": Already have image (with digest): gcr.io/cloud-builders/gcloud
Step #1 - "deploy": ERROR: (gcloud.functions.deploy) could not parse resource []
Finished Step #1 - "deploy"
ERROR
ERROR: build step 1 "gcr.io/cloud-builders/gcloud" failed: step exited with non-zero status: 1
Thanks Pritish