Last active
April 6, 2019 00:52
-
-
Save marcosborges/34508f4a22f6df576b515d33f009269d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
FROM google/cloud-sdk:alpine | |
RUN apk --update add openjdk7-jre | |
RUN gcloud components install app-engine-java kubectl |
This file contains hidden or 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
def _provisioningMysqlUserOnGcloud(host, instance, username, password) { | |
withCredentials([ | |
file (credentialsId: 'GCLOUD_SA', variable: "GCLOUD_SA") | |
]){ | |
configFileProvider( | |
[configFile(fileId: 'dockerfiles-gcloud-sdk.dockerfile', variable: 'GCLOUD_SDK_DOCKERFILE')] | |
) { | |
sh """ cp ${env.GCLOUD_SDK_DOCKERFILE} gCloudSDK.Dockerfile """ | |
def gcloudSDK = docker.build("gcloud-sdk-kubectl", "-f gCloudSDK.Dockerfile .") | |
gcloudSDK.inside(""" -e "CLOUDSDK_CONFIG=/tmp/mygcloud" -e "KUBECONFIG=/tmp/mykubectl" """) { | |
def data = readJSON file: "${env.GCLOUD_SA}" | |
sh """ gcloud config set project ${data['project_id']} """ | |
sh """ gcloud auth activate-service-account "${data['client_email']}" --key-file="${env.GCLOUD_SA}" --project="${data['project_id']}" """ | |
try{ | |
sh """ gcloud sql users create ${username} --host="${host}" --instance="${instance}" --password="${password}" """ | |
return true | |
} catch(e) { | |
return false | |
} | |
} | |
} | |
} | |
} | |
node{ | |
_provisioningMysqlUserOnGcloud( | |
"%", | |
"dev", | |
"new_user", | |
"new_user_password" | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment