jenkins-pipelines/scripts/configure-build.sh

99 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright (c) 2022 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
set -e
source $(dirname "$0")/lib/job_utils.sh
load_build_env
# Convert $TIMESTAMP to a string similar to
# 2022-09-09 14:29:05 +0000
# Accepts timestamps similar to:
# 2022-09-08_18-00-07
# 20220909T034458Z
normalize_timestamp() {
local str="$1"
local norm
# $1:yr $2:mon $3:day $4 $5:hr $6:min $7:sec $8:TZ
str="$(echo "$str" | sed -r 's/^\s*([0-9]{4})-?([0-9]{2})-?([0-9]{2})([T_-]|\s+)([0-9]{2})-?([0-9]{2})-?([0-9]{2})\s*([zZ]|([+-][0-9]{4}))?.*$/\1-\2-\3T\5:\6:\7\8/')"
str="$(echo "$str" | sed -r 's/([0-9])[zZ]$/\1+0000/')"
if ! echo "$str" | grep -q -E '[+-][0-9]{4}$' ; then
local tz_offset
tz_offset="$(date --date="$str" '+%z')" || return 1
str+="$tz_offset"
fi
date="$(date --date="$str" --utc +'%Y-%m-%d %H:%M:%S +0000')" || return 1
echo "$date"
}
build_date="$(normalize_timestamp "$TIMESTAMP")" || exit 1
######################################################
# BUILD file
######################################################
build_info_file="$WORKSPACE_ROOT/BUILD"
release_info_file="${REPO_ROOT}/${RELEASE_INFO_FILE}"
if [[ -n "$SW_VERSION" ]] ; then
sw_version="$SW_VERSION"
elif [[ -n "$release_info_file" ]] ; then
sw_version=$(grep "PLATFORM_RELEASE=" "$release_info_file" | cut -d = -f 2 | tr -d '"')
[[ -n "$sw_version" ]] || die "unable to determine SW_VERSION"
else
die "unable to determine SW_VERSION"
fi
cat >"$build_info_file" <<_END
SW_VERSION="$sw_version"
BUILD_TARGET="Host Installer"
BUILD_TYPE="Formal"
BUILD_ID="$TIMESTAMP"
SRC_BUILD_ID="$BUILD_NUMBER"
JOB="$MASTER_JOB_NAME"
BUILD_BY="$USER"
BUILD_NUMBER="$MASTER_BUILD_NUMBER"
BUILD_HOST="$HOSTNAME"
BUILD_DATE="$build_date"
_END
notice "$build_info_file"
cat "$build_info_file"
######################################################
# stx.conf
######################################################
cd "$BUILD_HOME/repo/stx-tools"
rm -f stx.conf
unset DEBIAN_DISTRIBUTION DEBIAN_SNAPSHOT DEBIAN_SECURITY_SNAPSHOT
source ./import-stx
stx config --add builder.myuname "$USER"
stx config --add builder.uid "$USER_ID"
# Embedded in ~/localrc of the build container
stx config --add project.gituser "$USER_NAME"
stx config --add project.gitemail $USER_EMAIL
# This will be included in the name of your build container and the basename for $MY_REPO_ROOT_DIR
stx config --add project.name "$PROJECT"
stx config --add project.proxy false
# debian distro & urls
if [[ -n "$DEBIAN_SNAPSHOT_BASE" ]] ; then
stx config --add project.debian_snapshot_base "$DEBIAN_SNAPSHOT_BASE"
fi
if [[ -n "$DEBIAN_SECURITY_SNAPSHOT_BASE" ]] ; then
stx config --add project.debian_security_snapshot_base "$DEBIAN_SECURITY_SNAPSHOT_BASE"
fi
notice "$PWD/stx.conf"
cat stx.conf