3

My goal is to deploy a Cloud Function using Cloud Build. My cloudbuild.yaml looks as follows:

steps:
- name: gcr.io/cloud-builders/gcloud
  args: 
    [
      'functions', 'deploy', 'func3',
      '--region=us-central1',
      '--allow-unauthenticated',
      '--entry-point=helloWorld',
      '--runtime=nodejs8',
      '--source=https://source.developers.google.com/projects/XXX/repos/myfunc',
      '--trigger-http',
      '--service-account=XXX@appspot.gserviceaccount.com'
    ]

When I submit the build, the following is logged:

Created [https://cloudbuild.googleapis.com/v1/projects/XXX/builds/5ba01de5-b4ad-4489-b4b9-687d3a6fd8fa].
Logs are available at [https://console.cloud.google.com/gcr/builds/5ba01de5-b4ad-4489-b4b9-687d3a6fd8fa?project=YYY].
------------------------------------------------------------------------------------ REMOTE BUILD OUTPUT ------------------------------------------------------------------------------------
starting build "5ba01de5-b4ad-4489-b4b9-687d3a6fd8fa"

FETCHSOURCE
BUILD
Already have image (with digest): gcr.io/cloud-builders/gcloud
ERROR: (gcloud.functions.deploy) unrecognized arguments: --allow-unauthenticated 

To search the help text of gcloud commands, run:
  gcloud help -- SEARCH_TERMS
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/gcloud" failed: exit status 2
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

ERROR: (gcloud.builds.submit) build 5ba01de5-b4ad-4489-b4b9-687d3a6fd8fa completed with status "FAILURE"

As we can see, we fail. If I remove the line which references --allow-unauthenticated all proceeds correctly. For completeness, here is the working cloudbuild.yaml.

steps:
- name: gcr.io/cloud-builders/gcloud
  args: 
    [
      'functions', 'deploy', 'func3',
      '--region=us-central1',
      '--entry-point=helloWorld',
      '--runtime=nodejs8',
      '--source=https://source.developers.google.com/projects/XXX/repos/myfunc',
      '--trigger-http',
      '--service-account=XXX@appspot.gserviceaccount.com'
    ]

I have checked the gcloud documentation on gcloud functions deploy found here and can't see any typos or other trivial errors. I have been assuming that running gcloud as a Cloud Builder step would be identical to running it manually.

If I run the command manually (including the --allow-unauthenticated) it works without error. For example, if I run:

#!/bin/bash
gcloud functions deploy func3 \
    --region=us-central1 \
    --allow-unauthenticated \
    --entry-point=helloWorld \
    --runtime=nodejs8 \
    --source=https://source.developers.google.com/projects/XXX/repos/myfunc \
    --trigger-http \
    --service-account=XXX@appspot.gserviceaccount.com

... there are no issues.

The core of the question is what might be the issue with the --allow-unauthenticated option within the context of Cloud Build?

4

2 回答 2

0

The error message might be a little misleading:

ERROR: (gcloud.functions.deploy) unrecognized arguments: --allow-unauthenticated

When running gcloud help functions deploy it lists --allow-unauthenticated as a valid flag:

--allow-unauthenticated
    If set, makes this a public function. This will allow all callers,
    without checking authentication.

As Travis commented... that this could be erroneous behavior isn't something I'd consider as "unlikely", since occasional glitches are nothing special when complex distributed systems are being updated.

于 2019-11-17T05:58:58.473 回答
0

It appears to be a transient issue caused by a faulty gcloud build image.

Use this version for now:

gcr.io/cloud-builders/gcloud@sha256:4ea77d19d7336d5a8dc4ae0e609d7f5b45fca067c34b70d7ed6740af229392c6
于 2019-11-17T07:40:46.307 回答