11def workpath_linux = " /src/github.com/deis/workflow-cli"
2- def keyfile = " tmp/key.json"
32
43def getBasePath = { String filepath ->
54 def filename = filepath. lastIndexOf(File . separator)
@@ -15,11 +14,27 @@ def make = { String target ->
1514 }
1615}
1716
18- def upload_artifacts = { String filepath ->
17+ def gcs_cleanup_cmd = " sh -c 'rm -rf /.config/*'"
18+ def gcs_bucket = " gs://workflow-cli"
19+ def gcs_key = " tmp/key.json"
20+
21+ def gcs_cmd = { String cmd ->
22+ gcs_cmd = " docker run --rm -v ${ pwd()} /tmp:/.config -v ${ pwd()} /_dist:/upload google/cloud-sdk:latest "
23+ try {
24+ sh(gcs_cmd + cmd)
25+ } catch (error) {
26+ sh(gcs_cmd + gcs_cleanup_cmd)
27+ error ' gcs error'
28+ }
29+ }
30+
31+ def upload_artifacts = {
1932 withCredentials([[$class : ' FileBinding' , credentialsId : ' e80fd033-dd76-4d96-be79-6c272726fb82' , variable : ' GCSKEY' ]]) {
20- sh " mkdir -p ${ getBasePath(filepath)} "
21- sh " cat \"\$ {GCSKEY}\" > ${ filepath} "
22- make ' upload-gcs'
33+ sh " mkdir -p ${ getBasePath(gcs_key)} "
34+ sh " cat \"\$ {GCSKEY}\" > ${ gcs_key} "
35+ gcs_cmd ' gcloud auth activate-service-account -q --key-file /.config/key.json'
36+ gcs_cmd " gsutil -mq cp -a public-read -r /upload/* ${ gcs_bucket} "
37+ gcs_cmd gcs_cleanup_cmd
2338 }
2439}
2540
@@ -128,7 +143,7 @@ parallel(
128143 env. VERSION = git_commit. take(7 )
129144 make ' build-revision'
130145
131- upload_artifacts(keyfile )
146+ upload_artifacts()
132147 }
133148 }
134149 },
@@ -144,7 +159,7 @@ parallel(
144159 make ' bootstrap'
145160 make ' build-latest'
146161
147- upload_artifacts(keyfile )
162+ upload_artifacts()
148163 } else {
149164 echo " Skipping build of latest artifacts because this build is not on the master branch (branch: ${ git_branch} )"
150165 }
0 commit comments