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