Merge "Deprecate legacy test task"
[releng.git] / jjb / kvmfornfv / kvmfornfv-upload-artifact.sh
1 #!/bin/bash
2 set -o errexit
3 set -o nounset
4
5 if [[ "$JOB_NAME" =~ (verify|merge|daily|weekly) ]]; then
6     JOB_TYPE=${BASH_REMATCH[0]}
7 else
8     echo "Unable to determine job type!"
9     exit 1
10 fi
11
12 case "$JOB_TYPE" in
13     verify)
14        OPNFV_ARTIFACT_VERSION="gerrit-$GERRIT_CHANGE_NUMBER"
15        GS_UPLOAD_LOCATION="gs://artifacts.opnfv.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"
16        echo "Removing outdated artifacts produced for the previous patch for the change $GERRIT_CHANGE_NUMBER"
17        gsutil ls $GS_UPLOAD_LOCATION > /dev/null 2>&1 && gsutil rm -r $GS_UPLOAD_LOCATION
18        echo "Uploading artifacts for the change $GERRIT_CHANGE_NUMBER. This could take some time..."
19        ;;
20     daily)
21         echo "Uploading daily artifacts This could take some time..."
22         OPNFV_ARTIFACT_VERSION=$(date -u +"%Y-%m-%d_%H-%M-%S")
23         GS_UPLOAD_LOCATION="gs://$GS_URL/$OPNFV_ARTIFACT_VERSION"
24         GS_LOG_LOCATION="gs://$GS_URL/logs-$(date -u +"%Y-%m-%d")/
25         ;;
26     *)
27         echo "Artifact upload is not enabled for $JOB_TYPE jobs"
28         exit 1
29 esac
30
31 # save information regarding artifacts into file
32 (
33     echo "OPNFV_ARTIFACT_VERSION=$OPNFV_ARTIFACT_VERSION"
34     echo "OPNFV_GIT_URL=$(git config --get remote.origin.url)"
35     echo "OPNFV_GIT_SHA1=$(git rev-parse HEAD)"
36     echo "OPNFV_ARTIFACT_URL=$GS_UPLOAD_LOCATION"
37     echo "OPNFV_BUILD_URL=$BUILD_URL"
38 ) > $WORKSPACE/opnfv.properties
39 source $WORKSPACE/opnfv.properties
40
41 # upload artifacts
42 if [[ "$PHASE" == "build" ]]; then
43     gsutil cp -r $WORKSPACE/build_output/* $GS_UPLOAD_LOCATION > $WORKSPACE/gsutil.log 2>&1
44     gsutil -m setmeta -r \
45         -h "Cache-Control:private, max-age=0, no-transform" \
46         $GS_UPLOAD_LOCATION > /dev/null 2>&1
47 else
48     if [[ "$JOB_TYPE" == "daily" ]]; then
49         log_dir=$WORKSPACE/build_output/log
50         if [[ -d "$log_dir" ]]; then
51             #Uploading logs to artifacts
52             echo "Uploading artifacts for future debugging needs...."
53             gsutil cp -r $WORKSPACE/build_output/log-*.tar.gz $GS_LOG_LOCATION > $WORKSPACE/gsutil.log 2>&1
54         else
55             echo "No test logs/artifacts available for uploading"
56         fi
57     fi
58 fi
59
60 # upload metadata file for the artifacts built by daily job
61 if [[ "$JOB_TYPE" == "daily" ]]; then
62     gsutil cp $WORKSPACE/opnfv.properties $GS_UPLOAD_LOCATION/opnfv.properties > $WORKSPACE/gsutil.log 2>&1
63     gsutil cp $WORKSPACE/opnfv.properties gs://$GS_URL/latest.properties > $WORKSPACE/gsutil.log 2>&1
64     gsutil -m setmeta -r \
65         -h "Cache-Control:private, max-age=0, no-transform" \
66         $GS_UPLOAD_LOCATION/opnfv.properties \
67         gs://$GS_URL/latest.properties > /dev/null 2>&1
68 fi
69
70 gsutil ls $GS_UPLOAD_LOCATION > /dev/null 2>&1
71 if [[ $? -ne 0 ]]; then
72     echo "Problem while uploading artifacts!"
73     echo "Check log $WORKSPACE/gsutil.log on $NODE_NAME"
74     exit 1
75 fi
76 echo "Uploaded artifacts!"