Commit 90f9c83d authored by Ryan Hitchman's avatar Ryan Hitchman

Make upload-to-gcs.sh include BUILD_METADATA_* env vars in started.json.

This is initially intended for storing GCI image versions. Example output: $ TEST_STARTED_JSON=1 BUILD_METADATA_GCE_IMAGE=m53 \ BUILD_METADATA_VARIANT=reliableforreal BUILD_NUMBER=123 \ WORKSPACE="blaga" JOB_NAME="test-e2e" hack/jenkins/upload-to-gcs.sh { "version": "v1.5.0-alpha.0.806+fa943089-dirty", "timestamp": 1473894301, "metadata": { "gce_image": "m53", "variant": "reliableforreal" }, "jenkins-node": "" }
parent fa943089
......@@ -31,6 +31,8 @@
# Note: for magicfile support to work correctly, the "file" utility must be
# installed.
# TODO(rmmh): rewrite this script in Python so we can actually test it!
set -o errexit
set -o nounset
set -o pipefail
......@@ -102,6 +104,35 @@ function find_version() {
)
}
# Output started.json. Use test function below!
function print_started() {
local metadata_keys=$(compgen -e | grep ^BUILD_METADATA_)
echo "{"
echo " \"version\": \"${version}\","
echo " \"timestamp\": ${timestamp},"
if [[ -n "${metadata_keys}" ]]; then
# Any exported variables of the form BUILD_METADATA_KEY=VALUE
# will be available as started["metadata"][KEY.lower()].
echo " \"metadata\": {"
local sep="" # leading commas are easy to track
for env_var in $metadata_keys; do
local var_upper="${env_var#BUILD_METADATA_}"
echo " $sep\"${var_upper,,}\": \"${!env_var}\""
sep=","
done
echo " },"
fi
echo " \"jenkins-node\": \"${NODE_NAME:-}\""
echo "}"
}
# Use this to test changes to print_started.
if [[ -n "${TEST_STARTED_JSON:-}" ]]; then
version=$(find_version)
cat <(print_started) | jq .
exit
fi
function upload_version() {
local -r version=$(find_version)
local upload_attempt
......@@ -117,13 +148,7 @@ function upload_version() {
local -r json_file="${gcs_build_path}/started.json"
for upload_attempt in {1..3}; do
echo "Uploading version to: ${json_file} (attempt ${upload_attempt})"
gsutil -q -h "Content-Type:application/json" cp -a "${gcs_acl}" <(
echo "{"
echo " \"version\": \"${version}\","
echo " \"timestamp\": ${timestamp},"
echo " \"jenkins-node\": \"${NODE_NAME:-}\""
echo "}"
) "${json_file}" || continue
gsutil -q -h "Content-Type:application/json" cp -a "${gcs_acl}" <(print_started) "${json_file}" || continue
break
done
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment