Initial commit for TF-A CI scripts
Signed-off-by: Fathi Boudra <fathi.boudra@linaro.org>
diff --git a/script/scratch_scripts/README b/script/scratch_scripts/README
new file mode 100644
index 0000000..590071b
--- /dev/null
+++ b/script/scratch_scripts/README
@@ -0,0 +1,9 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+The scripts in this folder are a copy of the scripts in the projectscratch
+folder. They should be kept in sync, deploy_scratch.sh is a helper script
+to copy them over.
diff --git a/script/scratch_scripts/delete_old_workspaces.sh b/script/scratch_scripts/delete_old_workspaces.sh
new file mode 100755
index 0000000..d34873e
--- /dev/null
+++ b/script/scratch_scripts/delete_old_workspaces.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Cleanup work spaces older than a day
+cd /arm/projectscratch/ssg/trusted-fw/ci-workspace
+find -maxdepth 1 \( -not -name . -a -mtime +1 \) -exec rm -rf '{}' +
diff --git a/script/scratch_scripts/deploy_scratch.sh b/script/scratch_scripts/deploy_scratch.sh
new file mode 100755
index 0000000..0c39ab8
--- /dev/null
+++ b/script/scratch_scripts/deploy_scratch.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+ci_root="$(readlink -f "$(dirname "$0")/../..")"
+source "$ci_root/utils.sh"
+
+if ! ls $project_filer/ci-scripts/
+then
+ echo "make sure /arm is mounted, if it is not, it can be mounted with the following command:" >&2
+ echo "sudo sshfs [USER]@login1.euhpc2.arm.com:/arm /arm -o allow_other,reconnect" >&2
+ echo "note that the euhpc and euhpc2 have different /arm mounts" >&2
+ exit 1
+fi
+
+COMMAND="cp $ci_root/script/scratch_scripts/* $project_filer/ci-scripts/"
+FILES=`ls -al "$ci_root"/script/scratch_scripts/*`
+
+echo "files to be copied:"
+echo "$FILES"
+echo ""
+echo "####DANGER### POTENTIAL FOR DAMAGE, CHECK THIS COMMAND"
+echo "command to be run: \"$COMMAND\""
+read -p "Run this command [Y/n]: "
+echo
+if [[ $REPLY =~ ^[Yy]$ ]]
+then
+ eval "$COMMAND"
+fi
diff --git a/script/scratch_scripts/initial_clone.sh b/script/scratch_scripts/initial_clone.sh
new file mode 100755
index 0000000..94c9de5
--- /dev/null
+++ b/script/scratch_scripts/initial_clone.sh
@@ -0,0 +1,87 @@
+#!/bin/bash
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# This script is meant to be run from Jenkins to make an initial clone of the
+# CI repository.
+#
+# - If CI_ROOT is set, we assume that a parent job has already cloned required
+# repositories; so we skip further cloning. However, in order to prevent this
+# job from potentially cleaning up the filer workspace (which is the
+# responsibility of the parent job which did the original clone), we unset
+# the FILER_WS variable in the env file.
+#
+# - Otherwise, we call clone_repos.sh to have all required repositories to be
+# cloned.
+#
+# Note that, since this file resides in the repository itself, a copy of this
+# file must be 'wget'. I.e., any changes to to this file must be committed first
+# to the CI repository master for it to take effect!
+
+strip_var() {
+ local var="$1"
+ local val="$(echo "${!var}" | sed 's#^\s*\|\s*$##g')"
+ eval "$var=$val"
+}
+
+strip_var CI_REFSPEC
+
+if [ "$CI_ENVIRONMENT" ]; then
+ tmpfile="$(mktemp --tmpdir="$WORKSPACE")"
+ echo "$CI_ENVIRONMENT" > "$tmpfile"
+ set -a
+ source "$tmpfile"
+ set +a
+fi
+
+if [ "$CI_ROOT" ]; then
+ # We're not going to clone repos; so prevent this job from cleaning up
+ # filer workspace.
+ echo "FILER_WS=" > env
+
+ # Resetting a variable doesn't seem to work on new Jenkins instance. So
+ # us a different variable altogether instead.
+ echo "DONT_CLEAN_WS=1" >> env
+
+ exit 0
+fi
+
+# If no CI ref specs were explicitly specified, but was triggered from a CI
+# Gerrit trigger, move to the Gerrit refspec instead so that we use the expected
+# version of clone_repos.sh.
+if [ -z "$CI_REFSPEC" ] && [ "$REPO_UNDER_TEST" = "trusted-firmware-ci" ] && \
+ [ "$GERRIT_REFSPEC" ]; then
+ CI_REFSPEC="$GERRIT_REFSPEC"
+fi
+
+# Clone CI repository and move to the refspec
+git clone -q --depth 1 \
+ http://ssg-sw.cambridge.arm.com/gerrit/pdswinf/ci/pdcs-platforms/platform-ci
+
+if [ "$CI_REFSPEC" ]; then
+ # Only recent Git versions support fetching refs via. commit IDs.
+ # However, platform slaves have been updated to a version that can do
+ # this (https://jira.arm.com/browse/SSGSWINF-1426). The module load
+ # commands have been commented out since.
+ #
+ # source /arm/tools/setup/init/bash
+ # module load swdev
+ # module load git/git/2.14.3
+
+ pushd platform-ci &>/dev/null
+ git fetch -q --depth 1 origin "$CI_REFSPEC"
+ git checkout -q FETCH_HEAD
+ echo "CI repo checked out to $CI_REFSPEC"
+ popd &>/dev/null
+fi
+
+if ! platform-ci/trusted-fw/new-ci/script/clone_repos.sh; then
+ echo "clone_repos.sh failed!"
+ cat clone_repos.log
+ exit 1
+fi
+
+# vim:set tw=80 sw=8 sts=8 noet:
diff --git a/script/scratch_scripts/initial_clone_temp.sh b/script/scratch_scripts/initial_clone_temp.sh
new file mode 100755
index 0000000..ef762bf
--- /dev/null
+++ b/script/scratch_scripts/initial_clone_temp.sh
@@ -0,0 +1,123 @@
+#!/bin/bash
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# This script is meant to be run from Jenkins to make an initial clone of the
+# CI repository.
+#
+# - If CI_SCRATCH is set, we assume that a parent job has already cloned
+# required repositories; so we skip further cloning.
+#
+# - Otherwise, we call clone_repos.sh to have all required repositories to be
+# cloned.
+#
+# Note that, since this file resides in the repository itself, a copy of this
+# file must be 'wget'. I.e., any changes to to this file must be committed first
+# to the CI repository master for it to take effect!
+
+set -e
+set -x
+
+strip_var() {
+ local var="$1"
+ local val="$(echo "${!var}" | sed 's#^\s*\|\s*$##g')"
+ eval "$var=$val"
+}
+
+set_ci_root() {
+ export ci_root=`pwd`/"platform-ci"
+ export CI_ROOT=$ci_root
+}
+
+strip_var CI_REFSPEC
+
+if [ "$CI_ENVIRONMENT" ]; then
+ tmpfile="$(mktemp --tmpdir="$WORKSPACE")"
+ echo "$CI_ENVIRONMENT" | tr ' ' '\n' > "$tmpfile"
+ set -a
+ source "$tmpfile"
+ set +a
+fi
+
+if [ "$CI_SCRATCH" ]; then
+ if [ ! -d "$CI_SCRATCH" ]; then
+ echo "\$CI_SCRATCH is stale; ignored."
+ else
+ # Copy environment and parameter file from scratch to this job's
+ # workspace
+ cp "$CI_SCRATCH/env" .
+ cp "$CI_SCRATCH/env.param" .
+ find "$CI_SCRATCH" -name "*.data" -exec cp -t . '{}' +
+
+ exit 0
+ fi
+fi
+
+# If no CI ref specs were explicitly specified, but was triggered from a CI
+# Gerrit trigger, move to the Gerrit refspec instead so that we use the expected
+# version of clone_repos.sh.
+if [ -z "$CI_REFSPEC" ] && [ "$REPO_UNDER_TEST" = "trusted-firmware-ci" ] && \
+ [ "$GERRIT_REFSPEC" ]; then
+ export CI_REFSPEC="$GERRIT_REFSPEC"
+fi
+
+# Clone CI repository and move to the refspec
+if [ ! -d "platform-ci" ]
+then
+ git clone -q --depth 1 \
+ --reference /arm/projectscratch/ssg/trusted-fw/ref-repos/trusted-firmware-ci \
+ http://ssg-sw.cambridge.arm.com/gerrit/pdswinf/ci/pdcs-platforms/platform-ci
+else
+ pushd platform-ci
+ git fetch
+ popd
+fi
+
+# Set CI_ROOT as a fallback
+set_ci_root
+echo "CI_ROOT=$ci_root" >> env
+
+if [ "$CI_REFSPEC" ]; then
+ # Only recent Git versions support fetching refs via. commit IDs.
+ # However, platform slaves have been updated to a version that can do
+ # this (https://jira.arm.com/browse/SSGSWINF-1426). The module load
+ # commands have been commented out since.
+ #
+ # source /arm/tools/setup/init/bash
+ # module load swdev
+ # module load git/git/2.14.3
+
+ # Translate refspec if supported
+ if [ -x "$ci_root/script/translate_refspec.py" ]; then
+ CI_REFSPEC="$("$ci_root/script/translate_refspec.py" \
+ -p trusted-firmware-ci "$CI_REFSPEC")"
+ fi
+
+ pushd platform-ci &>/dev/null
+ git fetch -q --depth 1 origin "$CI_REFSPEC"
+ git checkout -q FETCH_HEAD
+ echo
+ echo "Initial CI repo checked out to '$CI_REFSPEC'."
+ popd &>/dev/null
+fi
+
+if [ "$ci_only" ]; then
+ exit 0
+fi
+
+if echo "$-" | grep -q "x"; then
+ minus_x="-x"
+fi
+
+if ! bash $minus_x "$ci_root/script/clone_repos.sh"; then
+ echo "clone_repos.sh failed!"
+ cat clone_repos.log
+ exit 1
+fi
+
+set_ci_root
+
+# vim:set tw=80 sw=8 sts=8 noet:
diff --git a/script/scratch_scripts/initial_clone_v2.5.sh b/script/scratch_scripts/initial_clone_v2.5.sh
new file mode 100755
index 0000000..5630831
--- /dev/null
+++ b/script/scratch_scripts/initial_clone_v2.5.sh
@@ -0,0 +1,128 @@
+#!/bin/bash
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# This script is meant to be run from Jenkins to make an initial clone of the
+# CI repository.
+#
+# - If CI_SCRATCH is set, we assume that a parent job has already cloned
+# required repositories; so we skip further cloning.
+#
+# - Otherwise, we call clone_repos.sh to have all required repositories to be
+# cloned.
+#
+# Note that, since this file resides in the repository itself, a copy of this
+# file must be 'wget'. I.e., any changes to to this file must be committed first
+# to the CI repository master for it to take effect!
+
+set -e
+
+strip_var() {
+ local var="$1"
+ local val="$(echo "${!var}" | sed 's#^\s*\|\s*$##g')"
+ eval "$var=$val"
+}
+
+set_ci_root() {
+ ci_root=`pwd`/"platform-ci"
+ CI_ROOT=$ci_root
+}
+
+strip_var CI_REFSPEC
+
+if [ ! -z $PROJECT ]; then
+ export REPO_UNDER_TEST=`basename $PROJECT`
+ echo "REPO_UNDER_TEST is blank, but PROJECT is set, setting REPO_UNDER_TEST based on PROJECT"
+ echo "REPO_UNDER_TEST=$REPO_UNDER_TEST"
+ echo "REPO_UNDER_TEST=$REPO_UNDER_TEST" >> env
+fi
+
+if [ "$CI_ENVIRONMENT" ]; then
+ tmpfile="$(mktemp --tmpdir="$WORKSPACE")"
+ echo "$CI_ENVIRONMENT" | tr ' ' '\n' > "$tmpfile"
+ set -a
+ source "$tmpfile"
+ set +a
+fi
+
+if [ "$CI_SCRATCH" ]; then
+ if [ ! -d "$CI_SCRATCH" ]; then
+ echo "\$CI_SCRATCH is stale; ignored."
+ else
+ # Copy environment and parameter file from scratch to this job's
+ # workspace
+ cp "$CI_SCRATCH/env" .
+ cp "$CI_SCRATCH/env.param" .
+ find "$CI_SCRATCH" -name "*.data" -exec cp -t . '{}' +
+
+ exit 0
+ fi
+fi
+
+# If no CI ref specs were explicitly specified, but was triggered from a CI
+# Gerrit trigger, move to the Gerrit refspec instead so that we use the expected
+# version of clone_repos.sh.
+if [ -z "$CI_REFSPEC" ] && [ "$REPO_UNDER_TEST" = "trusted-firmware-ci" ] && \
+ [ "$GERRIT_REFSPEC" ]; then
+ export CI_REFSPEC="$GERRIT_REFSPEC"
+fi
+
+# Clone CI repository and move to the refspec
+if [ ! -d "platform-ci" ]
+then
+git clone -q --depth 1 \
+ --reference /arm/projectscratch/ssg/trusted-fw/ref-repos/trusted-firmware-ci \
+ http://ssg-sw.cambridge.arm.com/gerrit/pdswinf/ci/pdcs-platforms/platform-ci
+else
+ pushd platform-ci
+ git fetch
+ git checkout origin/master
+ popd
+fi
+
+set_ci_root
+# Set CI_ROOT as a fallback
+echo "CI_ROOT=$ci_root" >> env
+
+if [ "$CI_REFSPEC" ]; then
+ # Only recent Git versions support fetching refs via. commit IDs.
+ # However, platform slaves have been updated to a version that can do
+ # this (https://jira.arm.com/browse/SSGSWINF-1426). The module load
+ # commands have been commented out since.
+ #
+ # source /arm/tools/setup/init/bash
+ # module load swdev
+ # module load git/git/2.14.3
+
+ # Translate refspec if supported
+ if [ -x "$ci_root/script/translate_refspec.py" ]; then
+ CI_REFSPEC="$("$ci_root/script/translate_refspec.py" \
+ -p trusted-firmware-ci -s arm "$CI_REFSPEC")"
+ fi
+
+ pushd platform-ci &>/dev/null
+ git fetch -q --depth 1 origin "$CI_REFSPEC"
+ git checkout -q FETCH_HEAD
+ echo
+ echo "Initial CI repo checked out to '$CI_REFSPEC'."
+ popd &>/dev/null
+fi
+
+if [ "$ci_only" ]; then
+ exit 0
+fi
+
+if echo "$-" | grep -q "x"; then
+ minus_x="-x"
+fi
+
+if ! bash $minus_x "$ci_root/script/clone_repos.sh"; then
+ echo "clone_repos.sh failed!"
+ cat clone_repos.log
+ exit 1
+fi
+
+# vim:set tw=80 sw=8 sts=8 noet:
diff --git a/script/scratch_scripts/initial_clone_v2.sh b/script/scratch_scripts/initial_clone_v2.sh
new file mode 100755
index 0000000..0836fe1
--- /dev/null
+++ b/script/scratch_scripts/initial_clone_v2.sh
@@ -0,0 +1,108 @@
+#!/bin/bash
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# This script is meant to be run from Jenkins to make an initial clone of the
+# CI repository.
+#
+# - If CI_SCRATCH is set, we assume that a parent job has already cloned
+# required repositories; so we skip further cloning.
+#
+# - Otherwise, we call clone_repos.sh to have all required repositories to be
+# cloned.
+#
+# Note that, since this file resides in the repository itself, a copy of this
+# file must be 'wget'. I.e., any changes to to this file must be committed first
+# to the CI repository master for it to take effect!
+
+set -e
+
+strip_var() {
+ local var="$1"
+ local val="$(echo "${!var}" | sed 's#^\s*\|\s*$##g')"
+ eval "$var=$val"
+}
+
+strip_var CI_REFSPEC
+
+if [ "$CI_ENVIRONMENT" ]; then
+ tmpfile="$(mktemp --tmpdir="$WORKSPACE")"
+ echo "$CI_ENVIRONMENT" | tr ' ' '\n' > "$tmpfile"
+ set -a
+ source "$tmpfile"
+ set +a
+fi
+
+if [ "$CI_SCRATCH" ]; then
+ if [ ! -d "$CI_SCRATCH" ]; then
+ echo "\$CI_SCRATCH is stale; ignored."
+ else
+ # Copy environment and parameter file from scratch to this job's
+ # workspace
+ cp "$CI_SCRATCH/env" .
+ cp "$CI_SCRATCH/env.param" .
+ find "$CI_SCRATCH" -name "*.data" -exec cp -t . '{}' +
+
+ exit 0
+ fi
+fi
+
+# If no CI ref specs were explicitly specified, but was triggered from a CI
+# Gerrit trigger, move to the Gerrit refspec instead so that we use the expected
+# version of clone_repos.sh.
+if [ -z "$CI_REFSPEC" ] && [ "$REPO_UNDER_TEST" = "trusted-firmware-ci" ] && \
+ [ "$GERRIT_REFSPEC" ]; then
+ export CI_REFSPEC="$GERRIT_REFSPEC"
+fi
+
+# Clone CI repository and move to the refspec
+git clone -q --depth 1 \
+ --reference /arm/projectscratch/ssg/trusted-fw/ref-repos/trusted-firmware-ci \
+ http://ssg-sw.cambridge.arm.com/gerrit/pdswinf/ci/pdcs-platforms/platform-ci
+
+# Set CI_ROOT as a fallback
+ci_root="platform-ci/trusted-fw/new-ci"
+echo "CI_ROOT=$ci_root" >> env
+
+if [ "$CI_REFSPEC" ]; then
+ # Only recent Git versions support fetching refs via. commit IDs.
+ # However, platform slaves have been updated to a version that can do
+ # this (https://jira.arm.com/browse/SSGSWINF-1426). The module load
+ # commands have been commented out since.
+ #
+ # source /arm/tools/setup/init/bash
+ # module load swdev
+ # module load git/git/2.14.3
+
+ # Translate refpsec if supported
+ if [ -x "$ci_root/script/translate_refspec.py" ]; then
+ CI_REFSPEC="$("$ci_root/script/translate_refspec.py" \
+ -p trusted-firmware-ci "$CI_REFSPEC")"
+ fi
+
+ pushd platform-ci &>/dev/null
+ git fetch -q --depth 1 origin "$CI_REFSPEC"
+ git checkout -q FETCH_HEAD
+ echo
+ echo "Initial CI repo checked out to '$CI_REFSPEC'."
+ popd &>/dev/null
+fi
+
+if [ "$ci_only" ]; then
+ exit 0
+fi
+
+if echo "$-" | grep -q "x"; then
+ minus_x="-x"
+fi
+
+if ! bash $minus_x "$ci_root/script/clone_repos.sh"; then
+ echo "clone_repos.sh failed!"
+ cat clone_repos.log
+ exit 1
+fi
+
+# vim:set tw=80 sw=8 sts=8 noet:
diff --git a/script/scratch_scripts/initial_clone_v3.sh b/script/scratch_scripts/initial_clone_v3.sh
new file mode 100755
index 0000000..5f4e3fc
--- /dev/null
+++ b/script/scratch_scripts/initial_clone_v3.sh
@@ -0,0 +1,106 @@
+#!/bin/bash
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# This script is meant to be run from Jenkins to make an initial clone of the
+# CI repository.
+#
+# - If CI_SCRATCH is set, we assume that a parent job has already cloned
+# required repositories; so we skip further cloning.
+#
+# - Otherwise, we call clone_repos.sh to have all required repositories to be
+# cloned.
+#
+# Note that, since this file resides in the repository itself, a copy of this
+# file must be 'wget'. I.e., any changes to to this file must be committed first
+# to the CI repository master for it to take effect!
+
+set -e
+
+strip_var() {
+ local var="$1"
+ local val="$(echo "${!var}" | sed 's#^\s*\|\s*$##g')"
+ eval "$var=$val"
+}
+
+strip_var CI_REFSPEC
+
+if [ "$CI_ENVIRONMENT" ]; then
+ tmpfile="$(mktemp --tmpdir="$WORKSPACE")"
+ echo "$CI_ENVIRONMENT" | tr ' ' '\n' > "$tmpfile"
+ set -a
+ source "$tmpfile"
+ set +a
+fi
+
+if [ "$CI_SCRATCH" ]; then
+ if [ ! -d "$CI_SCRATCH" ]; then
+ echo "\$CI_SCRATCH is stale; ignored."
+ else
+ # Copy environment and parameter file from scratch to this job's
+ # workspace
+ cp "$CI_SCRATCH/env" .
+ cp "$CI_SCRATCH/env.param" .
+ find "$CI_SCRATCH" -name "*.data" -exec cp -t . '{}' +
+
+ exit 0
+ fi
+fi
+
+# If no CI ref specs were explicitly specified, but was triggered from a CI
+# Gerrit trigger, move to the Gerrit refspec instead so that we use the expected
+# version of clone_repos.sh.
+if [ -z "$CI_REFSPEC" ] && [ "$REPO_UNDER_TEST" = "tf-a-ci" ] && \
+ [ "$GERRIT_REFSPEC" ]; then
+ export CI_REFSPEC="$GERRIT_REFSPEC"
+fi
+
+ci_root=`pwd`/"tf-a-ci"
+# Clone CI repository and move to the refspec
+git clone -q --depth 1 \
+ --reference /arm/projectscratch/ssg/trusted-fw/ref-repos/tf-a-ci \
+ https://gerrit.oss.arm.com/trusted-firmware/tf-a-ci $ci_root
+
+# Set CI_ROOT as a fallback
+echo "CI_ROOT=$ci_root" >> env
+export CI_ROOT=$ci_root
+echo "CI_ROOT:"$CI_ROOT
+
+if [ "$CI_REFSPEC" ]; then
+ # Only recent Git versions support fetching refs via. commit IDs.
+ # However, platform slaves have been updated to a version that can do
+ # this (https://jira.arm.com/browse/SSGSWINF-1426). The module load
+ # commands have been commented out since.
+ #
+ # source /arm/tools/setup/init/bash
+ # module load swdev
+ # module load git/git/2.14.3
+
+ # Translate refpsec if supported
+ if [ -x "$ci_root/script/translate_refspec.py" ]; then
+ CI_REFSPEC="$("$ci_root/script/translate_refspec.py" \
+ -p tf-a-ci "$CI_REFSPEC")"
+ fi
+
+ pushd $ci_root &>/dev/null
+ git fetch -q --depth 1 origin "$CI_REFSPEC"
+ git checkout -q FETCH_HEAD
+ echo
+ echo "Initial CI repo checked out to '$CI_REFSPEC'."
+ popd &>/dev/null
+fi
+
+if [ "$ci_only" ]; then
+ exit 0
+fi
+
+if ! "$ci_root/script/clone_repos.sh"; then
+ echo "clone_repos.sh failed!"
+ cat clone_repos.log
+ exit 1
+fi
+
+# vim:set tw=80 sw=8 sts=8 noet:
diff --git a/script/scratch_scripts/post_build_setup.sh b/script/scratch_scripts/post_build_setup.sh
new file mode 100644
index 0000000..02741b3
--- /dev/null
+++ b/script/scratch_scripts/post_build_setup.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# THIS SCRIPT IS SOURCED!
+#
+# This script exists only to obtain a meaningful value for $CI_ROOT, the root
+# directory for CI scripts, from which other post-build scripts are executed.
+# Normally, $CI_ROOT *would* be available via. environment injection, but if a job
+# failed in its early stages, it wouldn't.
+
+# Although env file is meant to be sourced, RHS might have white spaces in it,
+# so sourcing will fail.
+set_ci_root() {
+ if [ -d "platform-ci/trusted-fw/new-ci" ]
+ then
+ ci_root="platform-ci/trusted-fw/new-ci"
+ else
+ ci_root="platform-ci"
+ fi
+}
+if [ -f "$WORKSPACE/env" ]; then
+ source "$WORKSPACE/env" 2>/dev/null || true
+fi
+
+if [ -z "$CI_ROOT" ] && [ -d "$WORKSPACE/platform-ci" ]; then
+ set_ci_root
+ CI_ROOT=$ci_root
+fi
+
+if [ -z "$CI_ROOT" ]; then
+ echo "warning: couldn't not determine value for \$CI_ROOT"
+fi
diff --git a/script/scratch_scripts/post_build_setup_v2.sh b/script/scratch_scripts/post_build_setup_v2.sh
new file mode 100644
index 0000000..9bf719a
--- /dev/null
+++ b/script/scratch_scripts/post_build_setup_v2.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# THIS SCRIPT IS SOURCED!
+#
+# This script exists only to obtain a meaningful value for $CI_ROOT, the root
+# directory for CI scripts, from which other post-build scripts are executed.
+# Normally, $CI_ROOT *would* be available via. environment injection, but if a job
+# failed in its early stages, it wouldn't.
+
+# Although env file is meant to be sourced, RHS might have white spaces in it,
+# so sourcing will fail.
+if [ -f "$WORKSPACE/env" ]; then
+ source "$WORKSPACE/env" 2>/dev/null || true
+fi
+
+if [ -z "$CI_ROOT" ] && [ -d "$WORKSPACE/tf-a-ci" ]; then
+ CI_ROOT="$WORKSPACE/tf-a-ci"
+fi
+
+if [ -z "$CI_ROOT" ]; then
+ echo "warning: couldn't not determine value for \$CI_ROOT"
+fi