5

I defined a source of a google cloud function as a google cloud repository. I changed my function source code, commit it and push into the repository by "git push --all google". I see a new version of the function code in the repository but the cloud function takes the old version.

So I need to deploy the new version of my function. I understood that I can't do it using console. When I try deploy it using SDK I recieve

gcloud functions deploy json_in_out --runtime nodejs8 --source https://source.developers.google.com/projects/mot_cz/repos/functions/demo/master/paths/json_in_out --trigger-http
ERROR: (gcloud.functions.deploy) ResponseError: status=[400], code=[Bad Request], message=[The request has errors
Problems:
Source repository URL is invalid https://source.developers.google.com/projects/mot_cz/repos/functions/demo/master/paths/json_in_out does not match the expected pattern
BT3
  • 433
  • 6
  • 21

2 Answers2

3

Pushing your code to Cloud Source Repository and deploying it as a new version of your Cloud Function are two different things, as @Doug Stevenson mentioned. However, you can easily automate this process with Cloud Build. A basic implementation involves 2 steps:

1.Add a cloudbuild.yaml file to your source code with the following:

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['functions', 'deploy', '[YOUR_DEPLOYED_FUNCTION_NAME]', '[YOUR_FUNCTION_TRIGGER]', '--runtime', '[YOUR_RUNTIME]', '--entry-point', '[YOUR_FUNCTION_NAME_IN_CODE]']

2.Create a build trigger in your Developer Console set up to deploy your code whenever you commit to a specific branch or tag on your repository.

You'll find a more complex use case here that involves testing in case you need it.

LundinCast
  • 9,412
  • 4
  • 36
  • 48
1

If you don't deploy your modified functions, no changes will take place. It's not enough to push the code to source control - you have to deploy the new code to start running it.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441