@@ -105,19 +105,32 @@ node('linux') {
105105 def gopath = gopath_linux()
106106 def workdir = workdir_linux(gopath, repo)
107107
108- // vars/closures around uploading artifacts to gcs
109- def keyfile = " tmp/key.json"
110-
111108 def getBasePath = { String filepath ->
112109 def filename = filepath. lastIndexOf(File . separator)
113110 return filepath. substring(0 , filename)
114111 }
115112
116- def upload_artifacts = { String filepath ->
113+ def gcs_cleanup_cmd = " sh -c 'rm -rf /.config/*'"
114+ def gcs_bucket = " gs://workflow-cli"
115+ def gcs_key = " tmp/key.json"
116+
117+ def gcs_cmd = { String cmd ->
118+ gcs_cmd = " docker run --rm -v ${ pwd()} /tmp:/.config -v ${ pwd()} /_dist:/upload google/cloud-sdk:latest "
119+ try {
120+ sh(gcs_cmd + cmd)
121+ } catch (error) {
122+ sh(gcs_cmd + gcs_cleanup_cmd)
123+ error ' gcs error'
124+ }
125+ }
126+
127+ def upload_artifacts = {
117128 withCredentials([[$class : ' FileBinding' , credentialsId : ' e80fd033-dd76-4d96-be79-6c272726fb82' , variable : ' GCSKEY' ]]) {
118- sh " mkdir -p ${ getBasePath(filepath)} "
119- sh " cat \"\$ {GCSKEY}\" > ${ filepath} "
120- make ' upload-gcs'
129+ sh " mkdir -p ${ getBasePath(gcs_key)} "
130+ sh " cat \"\$ {GCSKEY}\" > ${ gcs_key} "
131+ gcs_cmd ' gcloud auth activate-service-account -q --key-file /.config/key.json'
132+ gcs_cmd " gsutil -mq cp -a public-read -r /upload/* ${ gcs_bucket} "
133+ gcs_cmd gcs_cleanup_cmd
121134 }
122135 }
123136
@@ -145,7 +158,7 @@ node('linux') {
145158 sh " VERSION=${ git_commit.take(7)} make build-revision"
146159
147160 stage " Deploy ${ repo} "
148- upload_artifacts(keyfile )
161+ upload_artifacts()
149162 }
150163}
151164
0 commit comments