Skip to content

Instantly share code, notes, and snippets.

@mjackson
Last active May 25, 2022 13:56
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjackson/5887963e7d8b8fb0615416c510ae8857 to your computer and use it in GitHub Desktop.
Save mjackson/5887963e7d8b8fb0615416c510ae8857 to your computer and use it in GitHub Desktop.
Travis CI + google-cloud-sdk + updated kubectl + Docker
# The Google Cloud SDK on Travis is pretty old (2014). So if
# you want to use an up-to-date version, you have to install
# your own. This config is the bare minimum you'll need to
# get an updated version of the SDK + kubectl.
cache:
directories:
# We cache the SDK so we don't have to download it again on subsequent builds.
- $HOME/google-cloud-sdk
services:
# Include the docker service so you can roll your own images.
# You can remove this if you already have images somewhere else.
- docker
env:
global:
# Do not prompt for user input when using any SDK methods.
- CLOUDSDK_CORE_DISABLE_PROMPTS=1
before_install:
- if [ ! -d $HOME/google-cloud-sdk/bin ]; then
# The install script errors if this directory already exists,
# but Travis already creates it when we mark it as cached.
rm -rf $HOME/google-cloud-sdk;
# The install script is overly verbose, which sometimes causes
# problems on Travis, so ignore stdout.
curl https://sdk.cloud.google.com | bash > /dev/null;
fi
# This line is critical. We setup the SDK to take precedence in our
# environment over the old SDK that is already on the machine.
- source $HOME/google-cloud-sdk/path.bash.inc
- gcloud components update kubectl
- gcloud version
# Insert your own install + script below.
install: true
script: true
@OkThought
Copy link

Thanx, some of the solutions here helped me out :)
And by the way this travis config fails to parse due to comments included inside if statement

@jmeinke
Copy link

jmeinke commented Dec 19, 2018

@OkThought Thanks for your comment. Here is how I reformatted the if block to work with travis:

- if [ ! -d "$HOME/google-cloud-sdk/bin" ]; then rm -rf "$HOME/google-cloud-sdk"; curl https://sdk.cloud.google.com | bash > /dev/null; fi

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