Skip to content

Instantly share code, notes, and snippets.

Last active February 18, 2022 12:21
Show Gist options
  • Save satyadeepk/b0146a0ccefc87fc41a86ea7250ec23e to your computer and use it in GitHub Desktop.
Save satyadeepk/b0146a0ccefc87fc41a86ea7250ec23e to your computer and use it in GitHub Desktop.
Jenkins Google Cloud SDK install with auth script
export DIRECTORY="/var/jenkins_home/GoogleCloudSDK/google-cloud-sdk/bin"
if [ ! -d "$DIRECTORY" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
cd /var/jenkins_home
wget -O
unzip -o -d ./GoogleCloudSDK/
export PATH=/var/jenkins_home/GoogleCloudSDK/google-cloud-sdk/bin:$PATH
gcloud --quiet components update
gcloud --quiet components install beta
gcloud auth activate-service-account --key-file $GCLOUD_SERVICE_AUTH
gcloud config set project addodoc-1
gcloud beta test android run --app $WORKSPACE/app/build/outputs/apk/app-debug.apk --test $WORKSPACE/app/build/outputs/apk/app-debug-androidTest-unaligned.apk --results-bucket cloud-test-jenkins
Copy link

hi bro, how did you set $GCLOUD_SERVICE_AUTH? via parameter?

Copy link

For anyone who was looking for the answer to the above question. Create a secret file and upload the JSON key file through the Bindings section. All of this was done through the Job Configuration screen.
screen shot 2018-08-07 at 10 21 41 am

Copy link

Not sure if it would be helpful, but here is how I use it in my project and it is very helpful

pipeline {
agent any

environment {
    GOOGLE_PROJECT_ID = 'test-prj-cmd';

	GOOGLE_SERVICE_ACCOUNT_KEY = credentials('service_account_key');


			sh """
				echo "deploy stage";
				curl -o /tmp/google-cloud-sdk.tar.gz;
				tar -xvf /tmp/google-cloud-sdk.tar.gz -C /tmp/;
				/tmp/google-cloud-sdk/ -q;
				source /tmp/google-cloud-sdk/;
				 gcloud config set project ${GOOGLE_PROJECT_ID};
				 gcloud components install app-engine-java;
				 gcloud components install app-engine-python;
				 gcloud auth activate-service-account --key-file ${GOOGLE_SERVICE_ACCOUNT_KEY};
				 echo "After authentication gcloud";
				 gcloud config list;
				 mvn -X clean package appengine:deploy -Dmaven.test.failure.ignore=true;
				println "Result : ${currentBuild.result}";
				println "Deploy to GCP ..";


Note: If you need more gcloud components to be installed please go ahead and install in the sh section. I am trying to figure out how to have the gcloud instance available for the entire set of jenkins job type (like a maven/git/jdk tool) instead of plainly using docker to do that

Copy link

yog560 commented Apr 24, 2019

@vijaykumar.. how did you pass service_account_key (json file)... ?

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