Skip to content

Instantly share code, notes, and snippets.

@DennisAlund
Created August 27, 2016 15:14
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save DennisAlund/4285f7d9e8ea306e967820f1e439aa4e to your computer and use it in GitHub Desktop.
Save DennisAlund/4285f7d9e8ea306e967820f1e439aa4e to your computer and use it in GitHub Desktop.
Automatic deployment of Google App Engine project with Gitlab Continuous Integration - https://medium.com/evenbit/an-easy-guide-to-automatically-deploy-your-google-app-engine-project-with-gitlab-ci-48cb84757125
image: python:2.7
before_script:
- echo "deb http://packages.cloud.google.com/apt cloud-sdk-jessie main" | tee /etc/apt/sources.list.d/google-cloud-sdk.list
- curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
- apt-get update && apt-get install google-cloud-sdk
after_script:
- rm /tmp/$CI_PIPELINE_ID.json
deploy_production:
stage: deploy
environment: Production
only:
- master
script:
- echo $DEPLOY_KEY_FILE_PRODUCTION > /tmp/$CI_PIPELINE_ID.json
- gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json
- gcloud --quiet --project $PROJECT_ID_PRODUCTION app deploy
@SuppieRK
Copy link

SuppieRK commented Sep 12, 2017

Quick notes after trying:

  • there should be apt-get install -y google-cloud-sdk, otherwise build would stop
  • before executing deploy, you should CD into the project directory, usually /builds/TEAM_NAME/PROJECT_NAME
  • if you have flexible environment, at the current moment you would require following WA: gcloud config set app/use_deprecated_preparation True as provided here: GoogleCloudPlatform/getting-started-java#281
  • if you had specified separate folder for app.yaml file, last command must be gcloud --your_custom_properties app deploy ./path/to/app.yaml

@jayprakash1
Copy link

jayprakash1 commented Oct 16, 2017

I just had to do the first change apt-get install -y google-cloud-sdk to get build to work.

Copy link

ghost commented Sep 19, 2018

For some reason I get:

Running after script...
$ rm /tmp/$CI_PIPELINE_ID.json
rm: cannot remove '/tmp/12345.json': No such file or directory
ERROR: Job failed: exit code 1

@davux
Copy link

davux commented Oct 12, 2018

@bgold0, that's because the apt-get install step didn't work, so the job went from pre_script to post_script. As a result, the JSON file was never created so rm failed. If you use apt-get install -y it will be fixed. At any rate, if you don't want the rm bit to fail unnecessarily you can also change it to [ -e /tmp/$CI_PIPELINE_ID.json ] && rm /tmp/$CI_PIPELINE_ID.json.

Copy link

ghost commented Nov 2, 2018

@davux Thanks man, this seemed to work!

@schuyberg
Copy link

schuyberg commented Dec 22, 2018

instead of using the before script to install the google-cloud-sdk, it's possible to use image: google/cloud-sdk if you're running this on gitlab.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment