summaryrefslogtreecommitdiffstats
path: root/utils/push-test-logs.sh
blob: 590397f84b2a7e4d4074a1efe52e95edb61d6464 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2016 Orange and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set -e
set -o pipefail

export PATH=$PATH:/usr/local/bin/

git_sha1="$(git rev-parse HEAD)"
res_build_date=${1:-$(date -u +"%Y-%m-%d_%H-%M-%S")}
project=$PROJECT
branch=${GIT_BRANCH##*/}
testbed=$NODE_NAME
dir_result="${HOME}/opnfv/$project/results/$branch"
node_list=(\
'opnfv-jump-1' 'opnfv-jump-2' 'ericsson-pod1' 'ericsson-pod2' \
'intelpod2-jumphost' 'intel-pod3' 'intel-pod5' 'intel-pod6' \
'intel-pod8' 'huawei-us-deploy-bare-1')

if [[ ! " ${node_list[@]} " =~ " ${testbed} " ]]; then
    echo "This is not a CI POD. Aborting pushing the logs to artifacts."
    exit 0
fi

if [[ "$branch" == "master" ]]; then
    project_artifact=logs/$project/$testbed/$res_build_date
else
    project_artifact=logs/$project/$testbed/$branch/$res_build_date
fi

# create the folder to store the results
mkdir -p $dir_result

# copy folder to artifact
if [ -d "$dir_result" ]; then
    if [ "$(ls -A $dir_result)" ]; then
        set +e
        gsutil&>/dev/null
        if [ $? != 0 ]; then
            echo "Not possible to push results to artifact: gsutil not installed";
        else
            gsutil ls gs://artifacts.opnfv.org/"$project"/ &>/dev/null
            if [ $? != 0 ]; then
                echo "Not possible to push results to artifact: gsutil not installed.";
            else
                echo "copy result files to artifact $project_artifact"
                gsutil -m cp -r "$dir_result" gs://artifacts.opnfv.org/"$project_artifact"/
            fi
        fi
    else
          echo "Result folder is empty"
    fi
fi