@@ -8,10 +8,21 @@ source .buildkite/scripts/install_deps.sh
88source .buildkite/scripts/tooling.sh
99
1010cleanup () {
11+ local error_code=$?
12+
13+ if [ $error_code != 0 ] ; then
14+ # if variable is defined, run the logout
15+ if [ -n " ${GOOGLE_APPLICATION_CREDENTIALS+x} " ]; then
16+ google_cloud_logout_active_account
17+ fi
18+ fi
19+
1120 echo " Deleting temporal files..."
1221 cd ${WORKSPACE}
1322 rm -rf ${TMP_FOLDER_TEMPLATE_BASE} .*
1423 echo " Done."
24+
25+ exit $error_code
1526}
1627
1728trap cleanup EXIT
@@ -55,32 +66,28 @@ PACKAGE_STORAGE_INTERNAL_BUCKET_QUEUE_PUBLISHING_PATH="gs://elastic-bekitzur-pac
5566
5667
5768google_cloud_auth_signing () {
58- local gsUtilLocation=$( mktemp -d -p . -t ${TMP_FOLDER_TEMPLATE} )
69+ local gsUtilLocation=$( mktemp -d -p ${WORKSPACE} -t ${TMP_FOLDER_TEMPLATE} )
5970
6071 local secretFileLocation=${gsUtilLocation} /${GOOGLE_CREDENTIALS_FILENAME}
6172 echo " ${SIGNING_PACKAGES_GCS_CREDENTIALS_SECRET} " > ${secretFileLocation}
6273
6374 google_cloud_auth " ${secretFileLocation} "
64-
65- echo " ${gsUtilLocation} "
6675}
6776
6877google_cloud_auth_publishing () {
69- local gsUtilLocation=$( mktemp -d -p . -t ${TMP_FOLDER_TEMPLATE} )
78+ local gsUtilLocation=$( mktemp -d -p ${WORKSPACE} -t ${TMP_FOLDER_TEMPLATE} )
7079
7180 local secretFileLocation=${gsUtilLocation} /${GOOGLE_CREDENTIALS_FILENAME}
7281 echo " ${PACKAGE_UPLOADER_GCS_CREDENTIALS_SECRET} " > ${secretFileLocation}
7382
7483 google_cloud_auth " ${secretFileLocation} "
75-
76- echo " ${gsUtilLocation} "
7784}
7885
7986sign_package () {
8087 local package=${1}
8188 local packageZip=$( basename ${package} )
8289
83- local gsUtilLocation= $( google_cloud_auth_signing)
90+ google_cloud_auth_signing
8491
8592 # upload zip package (trailing forward slashes are required)
8693 echo " Upload package .zip file for signing ${package} to ${INFRA_SIGNING_BUCKET_ARTIFACTS_PATH} "
@@ -106,16 +113,15 @@ sign_package() {
106113
107114 ls -l " ${BUILD_PACKAGES_PATH} "
108115
109- echo " Removing temporal location ${gsUtilLocation} "
110- rm -r " ${gsUtilLocation} "
116+ google_cloud_logout_active_account
111117}
112118
113119publish_package () {
114120 local package=$1
115121 local packageZip=$( basename ${package} )
116122
117123 # create file with credentials
118- local gsUtilLocation= $( google_cloud_auth_publishing)
124+ google_cloud_auth_publishing
119125
120126 # upload files (trailing forward slashes are required)
121127 echo " Upload package .zip file ${package} to ${PACKAGE_STORAGE_INTERNAL_BUCKET_QUEUE_PUBLISHING_PATH} "
@@ -135,8 +141,7 @@ publish_package() {
135141
136142 popd > /dev/null
137143
138- echo " Removing temporal location ${gsUtilLocation} "
139- rm -r " ${gsUtilLocation} "
144+ google_cloud_logout_active_account
140145}
141146
142147add_bin_path
0 commit comments