blob: b8166f290c7aa7abdc22ef8dd002f97771c35099 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
3# Copyright (c) 2019, Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# This script is meant to be run from Jenkins to make an initial clone of the
9# CI repository.
10#
11# - If CI_ROOT is set, we assume that a parent job has already cloned required
12# repositories; so we skip further cloning. However, in order to prevent this
13# job from potentially cleaning up the filer workspace (which is the
14# responsibility of the parent job which did the original clone), we unset
15# the FILER_WS variable in the env file.
16#
17# - Otherwise, we call clone_repos.sh to have all required repositories to be
18# cloned.
19#
20# Note that, since this file resides in the repository itself, a copy of this
21# file must be 'wget'. I.e., any changes to to this file must be committed first
22# to the CI repository master for it to take effect!
23
24strip_var() {
25 local var="$1"
26 local val="$(echo "${!var}" | sed 's#^\s*\|\s*$##g')"
27 eval "$var=$val"
28}
29
30strip_var CI_REFSPEC
31
32if [ "$CI_ENVIRONMENT" ]; then
33 tmpfile="$(mktemp --tmpdir="$WORKSPACE")"
34 echo "$CI_ENVIRONMENT" > "$tmpfile"
35 set -a
36 source "$tmpfile"
37 set +a
38fi
39
40if [ "$CI_ROOT" ]; then
41 # We're not going to clone repos; so prevent this job from cleaning up
42 # filer workspace.
43 echo "FILER_WS=" > env
44
45 # Resetting a variable doesn't seem to work on new Jenkins instance. So
46 # us a different variable altogether instead.
47 echo "DONT_CLEAN_WS=1" >> env
48
49 exit 0
50fi
51
52# If no CI ref specs were explicitly specified, but was triggered from a CI
53# Gerrit trigger, move to the Gerrit refspec instead so that we use the expected
54# version of clone_repos.sh.
55if [ -z "$CI_REFSPEC" ] && [ "$REPO_UNDER_TEST" = "trusted-firmware-ci" ] && \
56 [ "$GERRIT_REFSPEC" ]; then
57 CI_REFSPEC="$GERRIT_REFSPEC"
58fi
59
60# Clone CI repository and move to the refspec
61git clone -q --depth 1 \
Zelalemd36c2d92020-08-04 16:59:47 -050062 https://gerrit.oss.arm.com/pdswinf/ci/pdcs-platforms/platform-ci
Fathi Boudra422bf772019-12-02 11:10:16 +020063
64if [ "$CI_REFSPEC" ]; then
65 # Only recent Git versions support fetching refs via. commit IDs.
66 # However, platform slaves have been updated to a version that can do
67 # this (https://jira.arm.com/browse/SSGSWINF-1426). The module load
68 # commands have been commented out since.
69 #
70 # source /arm/tools/setup/init/bash
71 # module load swdev
72 # module load git/git/2.14.3
73
74 pushd platform-ci &>/dev/null
75 git fetch -q --depth 1 origin "$CI_REFSPEC"
76 git checkout -q FETCH_HEAD
77 echo "CI repo checked out to $CI_REFSPEC"
78 popd &>/dev/null
79fi
80
81if ! platform-ci/trusted-fw/new-ci/script/clone_repos.sh; then
82 echo "clone_repos.sh failed!"
83 cat clone_repos.log
84 exit 1
85fi
86
87# vim:set tw=80 sw=8 sts=8 noet: