@@ -22,11 +22,12 @@ set -o errexit
22
22
set -o nounset
23
23
set -o pipefail
24
24
25
- source hack/lib/logging.sh
25
+ KUBE_ROOT=$( dirname " ${BASH_SOURCE[0]} " ) /../..
26
+ source " ${KUBE_ROOT} /hack/lib/logging.sh"
26
27
27
28
28
29
if [[ $# -eq 0 || ! $1 =~ ^[Yy]$ ]]; then
29
- read -p " Do you want to run gubernator.sh and upload logs publicly to GCS? [y/n]" yn
30
+ read -r - p " Do you want to run gubernator.sh and upload logs publicly to GCS? [y/n]" yn
30
31
echo
31
32
if [[ ! $yn =~ ^[Yy]$ ]]; then
32
33
exit 1
@@ -59,9 +60,9 @@ V=2 kube::log::status "Using bucket ${bucket_name}"
59
60
# Check if the bucket exists
60
61
if ! gsutil ls gs:// | grep -q " gs://${bucket_name} /" ; then
61
62
V=2 kube::log::status " Creating public bucket ${bucket_name} "
62
- gsutil mb gs://${bucket_name} /
63
+ gsutil mb " gs://${bucket_name} /"
63
64
# Make all files in the bucket publicly readable
64
- gsutil acl ch -u AllUsers:R gs://${bucket_name}
65
+ gsutil acl ch -u AllUsers:R " gs://${bucket_name} "
65
66
else
66
67
V=2 kube::log::status " Bucket already exists"
67
68
fi
79
80
80
81
# Get start and end timestamps based on build-log.txt file contents
81
82
# Line where the actual tests start
82
- start_line=$( grep -n -m 1 " ^=" ${BUILD_LOG_PATH} | sed ' s/\([0-9]*\).*/\1/' )
83
+ start_line=$( grep -n -m 1 " ^=" " ${BUILD_LOG_PATH} " | sed ' s/\([0-9]*\).*/\1/' )
83
84
# Create text file starting where the tests start
84
- after_start=$( tail -n +${start_line} ${BUILD_LOG_PATH} )
85
+ after_start=$( tail -n " +${start_line} " " ${BUILD_LOG_PATH} " )
85
86
echo " ${after_start} " >> build-log-cut.txt
86
87
# Match the first timestamp
87
88
start_time_raw=$( grep -m 1 -o ' [0-9][0-9][0-9][0-9][[:blank:]][0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]*' build-log-cut.txt)
88
89
rm build-log-cut.txt
89
90
# Make the date readable by date command (ex: 0101 00:00:00.000 -> 01/01 00:00:00.000)
90
- start_time=$( echo ${start_time_raw} | sed ' s/^.\{2\}/&\//' )
91
+ start_time=$( echo " ${start_time_raw} " | sed ' s/^.\{2\}/&\//' )
91
92
V=2 kube::log::status " Started at ${start_time} "
92
93
# Match the last timestamp in the build-log file
93
- end_time=$( grep -o ' [0-9][0-9][0-9][0-9][[:blank:]][0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]*' ${BUILD_LOG_PATH} | tail -1 | sed ' s/^.\{2\}/&\//' )
94
+ end_time=$( grep -o ' [0-9][0-9][0-9][0-9][[:blank:]][0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]*' " ${BUILD_LOG_PATH} " | tail -1 | sed ' s/^.\{2\}/&\//' )
94
95
# Convert to epoch time for Gubernator
95
96
start_time_epoch=$( date -d " ${start_time} " +%s)
96
97
end_time_epoch=$( date -d " ${end_time} " +%s)
97
98
98
99
# Make folder name for build from timestamp
99
- BUILD_STAMP=$( echo $ start_time | sed ' s/\///' | sed ' s/ /_/' )
100
+ BUILD_STAMP=$( echo " ${ start_time} " | sed ' s/\///' | sed ' s/ /_/' )
100
101
101
102
GCS_LOGS_PATH=" ${GCS_JOBS_PATH} /${BUILD_STAMP} "
102
103
@@ -108,11 +109,11 @@ if gsutil ls "${GCS_JOBS_PATH}" | grep -q "${BUILD_STAMP}"; then
108
109
exit
109
110
fi
110
111
111
- for result in $( find ${ARTIFACTS} -type d -name " results " ) ; do
112
- if [[ $result != " " && $result != " ${ARTIFACTS} /results" && $result != $ ARTIFACTS ]]; then
113
- mv $ result/ * $ ARTIFACTS
112
+ while IFS= read -r result ; do
113
+ if [[ $result != " " && $result != " ${ARTIFACTS} /results" && $result != " ${ ARTIFACTS} " ]]; then
114
+ mv " ${ result} / " * " ${ ARTIFACTS} "
114
115
fi
115
- done
116
+ done < <( find " ${ARTIFACTS} " -type d -name " results " )
116
117
117
118
# Upload log files
118
119
for upload_attempt in $( seq 3) ; do
@@ -137,7 +138,6 @@ version=""
137
138
if [[ -e " version" ]]; then
138
139
version=$( cat " version" )
139
140
elif [[ -e " hack/lib/version.sh" ]]; then
140
- export KUBE_ROOT=" ."
141
141
source " hack/lib/version.sh"
142
142
kube::version::get_version_vars
143
143
version=" ${KUBE_GIT_VERSION-} "
@@ -167,16 +167,21 @@ if [[ -e "${ARTIFACTS}/finished.json" ]]; then
167
167
fi
168
168
169
169
V=2 kube::log::status " Constructing started.json and finished.json files"
170
- echo " {" >> " ${ARTIFACTS} /started.json"
171
- echo " \" version\" : \" ${version} \" ," >> " ${ARTIFACTS} /started.json"
172
- echo " \" timestamp\" : ${start_time_epoch} ," >> " ${ARTIFACTS} /started.json"
173
- echo " \" jenkins-node\" : \" ${NODE_NAME:- } \" " >> " ${ARTIFACTS} /started.json"
174
- echo " }" >> " ${ARTIFACTS} /started.json"
175
-
176
- echo " {" >> " ${ARTIFACTS} /finished.json"
177
- echo " \" result\" : \" ${build_result} \" ," >> " ${ARTIFACTS} /finished.json"
178
- echo " \" timestamp\" : ${end_time_epoch} " >> " ${ARTIFACTS} /finished.json"
179
- echo " }" >> " ${ARTIFACTS} /finished.json"
170
+ cat << EOF >"${ARTIFACTS} /started.json"
171
+ {
172
+ "version": "${version} ",
173
+ "timestamp": ${start_time_epoch} ,
174
+ "jenkins-node": "${NODE_NAME:- } "
175
+ }
176
+ EOF
177
+
178
+
179
+ cat << EOF >"${ARTIFACTS} /finished.json"
180
+ {
181
+ "result": "${build_result} ",
182
+ "timestamp": ${end_time_epoch}
183
+ }
184
+ EOF
180
185
181
186
182
187
# Upload started.json
0 commit comments