1

I'm trying to get the gcloud command to work so i can run it in Jenkins, but i'm having troubles.

I'm running

gcloud --project=hv-match preview app deploy -q app.yaml --promote --verbosity debug --bucket gs://hv-match.appspot.com --version=1

And that produces this:

DEBUG: Running gcloud.preview.app.deploy with Namespace(__calliope_internal_deepest_parser=ArgumentParser(prog='
gcloud.preview.app.deploy', usage=None, description="*(BETA)* This command is used to deploy both code and confi
guration to the App Engine\nserver.  As an input it takes one or more ``DEPLOYABLES'' that should be\nuploaded. 
 A ``DEPLOYABLE'' can be a module's .yaml file or a configuration's\n.yaml file.", version=None, formatter_class
=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=False), account=None, bucket='gs://hv-matc
h.appspot.com', cmd_func=<bound method Command.Run of <googlecloudsdk.calliope.backend.Command object at 0x1cd01
10>>, command_path=['gcloud', 'preview', 'app', 'deploy'], configuration=None, deployables=['app.yaml'], docker_
build=None, document=None, env_vars=None, force=False, format=None, h=None, help=None, http_timeout=None, log_ht
tp=None, project='hv-match', promote=True, quiet=True, server=None, set_default=None, stop_previous_version=None
, trace_email=None, trace_log=False, trace_token=None, user_output_enabled=None, verbosity='debug', version='1')
.
ERROR: Argument [app.yaml] is not a valid deployable file.
DEBUG: (gcloud.preview.app.deploy) Errors occurred while parsing the App Engine app configuration.
Traceback (most recent call last):
  File "/usr/local/bin/../share/google/google-cloud-sdk/./lib/googlecloudsdk/calliope/cli.py", line 589, in Execute
    result = args.cmd_func(cli=self, args=args)
  File "/usr/local/bin/../share/google/google-cloud-sdk/./lib/googlecloudsdk/calliope/backend.py", line 1221, in Run
    resources = command_instance.Run(args)
  File "/usr/local/bin/../share/google/google-cloud-sdk/./lib/googlecloudsdk/appengine/app_commands/deploy.py", line 184, in Run
    args.deployables, project, args.version or util.GenerateVersionId())
  File "/usr/local/bin/../share/google/google-cloud-sdk/./lib/googlecloudsdk/appengine/lib/yaml_parsing.py", line 351, in __init__
    raise AppConfigSetLoadError()
AppConfigSetLoadError: Errors occurred while parsing the App Engine app configuration.
ERROR: (gcloud.preview.app.deploy) Errors occurred while parsing the App Engine app configuration.

And this is my app.yaml:

runtime: php55
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico
- url: /phpinfo.php
  script: phpinfo.php  
- url: /tabell.php
  script: tabell.php
- url: /lineup.php
  script: lineup.php
- url: /nextgame.php
  script: nextgame.php
- url: /pregame.php
  script: pregame.php
- url: /forumtext.php
  script: forumtext.php
- url: /livetabell.php
  script: livetabell.php
- url: /abbreviation.php
  script: abbreviation.php
- url: /SaveData.php
  script: SaveData.php
  login: admin
- url: /test.html
  script: test.html
- url: .*
  script: main.php
env_variables:
  apfykey: '*string-with-api-key*'

From googling i've run it down to that it could be related to Europe/US issues, i'm not sure where my project is lozalized but my VM is in the US at least. Or can it be something else?

Thanks in advance for any help!

EDIT WITH JENKINS OUTPUT

When i run the command above through Jenkins Execute Shell i get this output instead:

DEBUG: Running gcloud.preview.app.deploy with Namespace(__calliope_internal_deepest_parser=ArgumentParser(prog='gcloud.preview.app.deploy', usage=None, description="*(BETA)* This command is used to deploy both code and configuration to the App Engine\nserver.
As an input it takes one or more ``DEPLOYABLES'' that should be\nuploaded.  A ``DEPLOYABLE'' can be a module's .yaml file or a configuration's\n.yaml file.", version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error',
add_help=False), account=None, bucket='gs://hv-match.appspot.com', cmd_func=<bound method Command.Run of <googlecloudsdk.calliope.backend.Command object at 0x320c210>>, command_path=['gcloud', 'preview', 'app', 'deploy'], configuration=None,
deployables=['app.yaml'], docker_build=None, document=None, env_vars=None, force=False, format=None, h=None, help=None, http_timeout=None, log_http=None, project='hv-match', promote=True, quiet=True, server=None, set_default=None, stop_previous_version=None,
trace_email=None, trace_log=False, trace_token=None, user_output_enabled=None, verbosity='debug', version='1').
DEBUG: API endpoint: [https://appengine.googleapis.com/], API version: [v1beta4]
You are about to deploy the following modules:
 - hv-match/default (from [/opt/bitnami/apps/jenkins/jenkins_home/jobs/Deploy/workspace/app.yaml])
     Deployed URL: [https://hv-match.appspot.com]

Beginning deployment...
DEBUG: Using bucket [gs://hv-match.appspot.com].
INFO: Ignoring directory [.git]: Directory matches ignore regex.
INFO: Ignoring file [.gitignore]: File matches ignore regex.
DEBUG: Generated deployment manifest: "{
    *** removed for readability ***
}"
Copying files to Google Cloud Storage...
Synchronizing files to [gs://hv-match.appspot.com].
DEBUG: Running command: [/bin/bash /usr/local/share/google/google-cloud-sdk/bin/gsutil -m rsync -R -c /tmp/tmpPvL87s gs://hv-match.appspot.com], Env: [None]
Updating module [default]...DEBUG: Converted YAML to JSON: "{
    *** removed for readability ***
}"

Updating module [default]...failed.
DEBUG: (gcloud.preview.app.deploy) Error Response: [403] Request had insufficient authentication scopes.
Traceback (most recent call last):
  File "/usr/local/bin/../share/google/google-cloud-sdk/./lib/googlecloudsdk/calliope/cli.py", line 589, in Execute
    result = args.cmd_func(cli=self, args=args)
  File "/usr/local/bin/../share/google/google-cloud-sdk/./lib/googlecloudsdk/calliope/backend.py", line 1221, in Run
    resources = command_instance.Run(args)
  File "/usr/local/bin/../share/google/google-cloud-sdk/./lib/googlecloudsdk/appengine/app_commands/deploy.py", line 250, in Run
    images.get(module))
  File "/usr/local/bin/../share/google/google-cloud-sdk/./lib/googlecloudsdk/appengine/lib/appengine_api_client.py", line 73, in DeployModule
    self.client.apps_modules_versions.Create, create_request)
  File "/usr/local/bin/../share/google/google-cloud-sdk/./lib/googlecloudsdk/appengine/lib/api/requests.py", line 41, in MakeRequest
    raise exceptions.HttpException(ExtractErrorMessage(error_json))
HttpException: Error Response: [403] Request had insufficient authentication scopes.
ERROR: (gcloud.preview.app.deploy) Error Response: [403] Request had insufficient authentication scopes.
Build step 'Execute shell' marked build as failure
Finished: FAILURE

So something completely different, i'm at a loss here...

Output of gcloud version

Google Cloud SDK 0.9.82
app 2015.10.08
bq 2.0.18
bq-nix 2.0.18
core 2015.10.08
core-nix 2015.09.03
gcloud 2015.10.08
gsutil 4.15
gsutil-nix 4.14
MGJ
  • 147
  • 2
  • 12
  • The `app.yaml` looks okay, but what version of gcloud are you running and have you seen this message when you run it? `WARNING: The 'app run' command is deprecated and will soon be removed. Please use dev_appserver.py (in the same directory as the 'gcloud' command) instead.` – tx802 Oct 20 '15 at 09:48
  • I can't recall seeing that warning. If i run `gcloud version` i get `gcloud 2015.10.08`, i put the rest of the output in my original post. – MGJ Oct 20 '15 at 13:48
  • Are you sure that you're in the right directory? `Argument [app.yaml] is not a valid deployable file.` is an error message consistent with gcloud being unable to find `app.yaml`. Can you try running `cat app.yaml` in the same script, or specifying the full path in the `gcloud` invocation? – Zachary Newman Oct 20 '15 at 14:34
  • Yes, i've run `ls` as well as `cat app.yaml` prior to deploying and i can see all the files for my app there as well as the correct contents of the yaml file. – MGJ Oct 21 '15 at 05:17

2 Answers2

1

Request had insufficient scopes is a message that indicates that the authentication method your using doesn't have permission to perform all of the tasks you need to do.

If you're using a Jenkins instance hosted on a Google Compute Engine VM, you should either (1) create a new VM, and give it more permissive scopes, or (2) authenticate the Jenkins instance with a service account that has permission to access the App Engine and Compute Engine APIs.

We'll look into making these error messages more helpful.

Zachary Newman
  • 20,014
  • 4
  • 39
  • 37
  • I've added a service account with a JSON file, and added all variants of the email adress of the service account to the permissions for my app, yet still have that error. I'll try to create yet another VM then... – MGJ Oct 21 '15 at 05:17
  • `curl "http://metadata/computeMetadata/v1/instance/service-accounts/" -H "Metadata-Flavor: Google"` returns `############@project.gserviceaccount.com/` and `default/` – MGJ Oct 21 '15 at 05:21
  • Running `gcloud compute instances describe INSTANCE --format json` returns `Could not fetch resource: - Insufficient Permission` or `Unable to fetch a list of zones. Specifying [--zone] may fix this issue: - Insufficient Permission` depending on if i choose `y` or `n` at the prompt for `Did you mean zone [us-central1-a] for instances: [['[INSTANCE]']]?` – MGJ Oct 21 '15 at 05:24
  • The **final edit** at my [previos question](http://stackoverflow.com/questions/33164611/google-app-engine-google-cloud-console-jenkins-trigger-builds-remotely-gcloud) has the command that i used to create my Jenkins VM, i suspect this needs to be changed to get the correct scopes? I did not check the command properly and just ran it, which wasn't very smart i guess but i thought it was updated... – MGJ Oct 21 '15 at 05:31
0

Okay, i finally solved my problems! :)

In Google Cloud Shell i ran:

PASSWORD=###%%%&&&                                                # 12 or more chars, with letters and numbers
PROJECT_ID=**PROJECT**
BITNAMI_IMAGE=bitnami-jenkins-1-634-0-linux-debian-7-x86-64       # e.g. bitnami-jenkins-1-606-0-linux-debian-7-x86-64

gcloud compute \
instances create bitnami-jenkins2 \
--project ${PROJECT_ID} \
--image-project bitnami-launchpad \
--image ${BITNAMI_IMAGE} \
--zone us-central1-b \
--machine-type g1-small \
--metadata "bitnami-base-password=${PASSWORD},bitnami-default-user=CHANGEUSERNAMEHERE,bitnami-key=jenkins,bitnami-name=Jenkins,bitnami-url=//bitnami.com/stack/jenkins,bitnami-description=Jenkins,startup-script-url=https://dl.google.com/dl/jenkins/p2dsetup/setup-script.sh" \
--scopes "https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/compute,https://www,googleapis.com/auth/cloud.useraccounts,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/devstorage.full_control,https://www.googleapis.com/auth/projecthosting,https://www.googleapis.com/auth/appengine.admin" \
--tags "bitnami-launchpad"

This created my VM but with the wrong user since i changed my username with the command above (it was created with "user" anyway). So i had to find my config.xml and change the username to the correct one for all permissions and update the password, as well as renaming the folder for the default username folder "user" to the username i choose.

After that i was almost there, i had a missing API which i had to enable. I went to APIs and auth > APIs in the Cloud Console but couldn't find the App Engine Admin API i was tipped about here by Zachary (thanks again dude!), but i had missed you could search for 100+ APIs and the ones shown wasn't the only ones available so eventually i found it.

I also had to install some components for the gcloud command, this could be done by SSH'ing into the VM. I installed the [preview] and [app] components, as well as updating all the other default gcloud components.

My deploy just passed and updated my app, thanks a lot for all help ya'll!

Community
  • 1
  • 1
MGJ
  • 147
  • 2
  • 12