Last active
February 18, 2022 12:21
-
-
Save satyadeepk/b0146a0ccefc87fc41a86ea7250ec23e to your computer and use it in GitHub Desktop.
Jenkins Google Cloud SDK install with auth script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Ref: https://github.com/circleci/android-cloud-test-lab/blob/master/circle.yml | |
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 https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.zip -O google-cloud-sdk.zip | |
unzip -o google-cloud-sdk.zip -d ./GoogleCloudSDK/ | |
./GoogleCloudSDK/google-cloud-sdk/install.sh | |
fi | |
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 |
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');
}
stage('Deploy'){
steps{
sh """
echo "deploy stage";
curl -o /tmp/google-cloud-sdk.tar.gz https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-220.0.0-linux-x86_64.tar.gz;
tar -xvf /tmp/google-cloud-sdk.tar.gz -C /tmp/;
/tmp/google-cloud-sdk/install.sh -q;
source /tmp/google-cloud-sdk/path.bash.inc;
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;
"""
}
post{
always{
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
@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
hi bro, how did you set $GCLOUD_SERVICE_AUTH? via parameter?