68f80874ac4ccdd48a73245624dc87a018027499
[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
22 if [[ "$branch" == "master" ]]; then
23     project_artifact=logs/$project/$testbed/$res_build_date
24 else
25     project_artifact=logs/$project/$testbed/$branch/$res_build_date
26 fi
27
28 # create the folder to store the results
29 mkdir -p $dir_result
30
31 # copy folder to artifact
32 if [ -d "$dir_result" ]; then
33     if [ "$(ls -A $dir_result)" ]; then
34         set +e
35         gsutil&>/dev/null
36         if [ $? != 0 ]; then
37             echo "Not possible to push results to artifact: gsutil not installed";
38         else
39             gsutil ls gs://artifacts.opnfv.org/"$project"/ &>/dev/null
40             if [ $? != 0 ]; then
41                 echo "Not possible to push results to artifact: gsutil not installed.";
42             else
43                 echo "copy result files to artifact $project_artifact"
44                 gsutil -m cp -r "$dir_result" gs://artifacts.opnfv.org/"$project_artifact"/
45             fi
46         fi
47     else
48           echo "Result folder is empty"
49     fi
50 fi