Install gcloud on CodeShip - ShoppinPal/gcp-scripts GitHub Wiki
Install gcloud on your VM
In the setup commands area for CodeShip:
- Install gcloud:
export CLOUDSDK_PYTHON_SITEPACKAGES=1; export CLOUDSDK_CORE_DISABLE_PROMPTS=1; curl -s https://sdk.cloud.google.com | bash
- Reload the shell session:
source ~/.bashrc
- Make sure the tool was installed:
which gcloud
- Setup authentication and provide the VM's gcloud tool with the proper permissions
gcloud auth login –no-launch-browser- This will pause and give you a code which you can copy
- Paste it into a browser on your local machine and perform the authentication there
- Copy the final string from your browser back and paste it into the paused screen on the VM and then hit enter ... your authentication is done.
- Once authenticated in this way, the machine keeps the credentials until you change them.
-
If worried about losing the info from the above process (can’t think of a reason right now) ... then once the steps are done, save these files from the VM:
~/.config/gcloud/propertiesand~/.config/gcloud/credentialslocally. Then those can reused later as needed. -
For example, if you are using
Codeshipinstead ofJenkins, then those files can be created on every build via a one-line echo command in the setup part of the workflow.
echo '{ "data": [...], "file_version": 1}' > ~/.config/gcloud/credentials cat ~/.config/gcloud/credentials # proof that this was done right echo -e '[core]\naccount = [email protected]' > ~/.config/gcloud/properties cat ~/.config/gcloud/properties # proof that this was done right ``` 5. Verify credentials setup
- gcloud compute instances list --project $YOUR_PROJECT_ID
- it should show some results if you've setup the credentials properly