Deployment with gcloud CLI

2 minute read

Google Cloud deployments

Deployments to Google Cloud can be done using the gcloud CLI directly on a CloudBees CodeShip Basic build machine similar to how you might use the CLI locally.

You will need to configure your authentication with environment variables and then define the CLI commands you want to run as a custom-script deployment pipeline.

Installing The CLI

The gcloud CLI is pre-installed on CloudBees CodeShip Basic build machines.

If you want to update to the latest version at build time, add the following command in the Setup Commands section of your test settings:

gcloud components update --quiet

Configuring Authentication

Before you can run gcloud commands, you will need to run the appropriate gcloud authentication commands in your project’s setup commands or at the start of your custom-script deployment pipeline.

Google recommends using a service account for authentication. The easiest way to keep the authentication secure is to use environment variables to store the .json key file, and to pass that to your gcloud authentication commands.

As an example, create an environment variable called GOOGLE_KEY and paste the entire contents of your .json key file into it. Then in your deployment steps add the following to authenticate with the service account:

echo "${GOOGLE_KEY}" > "$HOME/clone/google-key.json" gcloud auth activate-service-account --key-file="$HOME/clone/google-key.json"

Deployment Scripting

You will need to create a new custom-script deployment pipeline to run the gcloud CLI commands you need for your deployment.

These commands will run every time the branch the deployment pipeline is associated with is updated. They are not CodeShip specific and will be standard gcloud CLI input.

gcloud CLI Information

Read more about the gcloud CLI for more information on using the CLI as well as complete documentation on what commands can be run with it.