Add hardcoded list of CI PODs to avoid pushing logs from non-CI PODs
[releng.git] / utils / push-test-logs.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Orange and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 set -e
11 set -o pipefail
12
13 export PATH=$PATH:/usr/local/bin/
14
15 git_sha1="$(git rev-parse HEAD)"
16 res_build_date=${1:-$(date -u +"%Y-%m-%d_%H-%M-%S")}
17 project=$PROJECT
18 branch=${GIT_BRANCH##*/}
19 testbed=$NODE_NAME
20 dir_result="${HOME}/opnfv/$project/results/$branch"
21 node_list=(\
22 'opnfv-jump-1' 'opnfv-jump-2' 'ericsson-pod1' 'ericsson-pod2' \
23 'intelpod2-jumphost' 'intel-pod3' 'intel-pod5' 'intel-pod6' \
24 'intel-pod8' 'huawei-us-deploy-bare-1')
25
26 if [[ ! " ${node_list[@]} " =~ " ${testbed} " ]]; then
27     echo "This is not a CI POD. Aborting pushing the logs to artifacts."
28     exit 0
29 fi
30
31 if [[ "$branch" == "master" ]]; then
32     project_artifact=logs/$project/$testbed/$res_build_date
33 else
34     project_artifact=logs/$project/$testbed/$branch/$res_build_date
35 fi
36
37 # create the folder to store the results
38 mkdir -p $dir_result
39
40 # copy folder to artifact
41 if [ -d "$dir_result" ]; then
42     if [ "$(ls -A $dir_result)" ]; then
43         set +e
44         gsutil&>/dev/null
45         if [ $? != 0 ]; then
46             echo "Not possible to push results to artifact: gsutil not installed";
47         else
48             gsutil ls gs://artifacts.opnfv.org/"$project"/ &>/dev/null
49             if [ $? != 0 ]; then
50                 echo "Not possible to push results to artifact: gsutil not installed.";
51             else
52                 echo "copy result files to artifact $project_artifact"
53                 gsutil -m cp -r "$dir_result" gs://artifacts.opnfv.org/"$project_artifact"/
54             fi
55         fi
56     else
57           echo "Result folder is empty"
58     fi
59 fi