Merge "KVMFORNFV: Enable artifact download and testing for daily job"
[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         ;;
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 gsutil cp -r $WORKSPACE/build_output/* $GS_UPLOAD_LOCATION > $WORKSPACE/gsutil.log 2>&1
42 gsutil -m setmeta -r \
43     -h "Cache-Control:private, max-age=0, no-transform" \
44     $GS_UPLOAD_LOCATION > /dev/null 2>&1
45
46 # upload metadata file for the artifacts built by daily job
47 if [[ "$JOB_TYPE" == "daily" ]]; then
48     gsutil cp $WORKSPACE/opnfv.properties $GS_UPLOAD_LOCATION/opnfv.properties > $WORKSPACE/gsutil.log 2>&1
49     gsutil cp $WORKSPACE/opnfv.properties gs://$GS_URL/latest.properties > $WORKSPACE/gsutil.log 2>&1
50     gsutil -m setmeta -r \
51         -h "Cache-Control:private, max-age=0, no-transform" \
52         $GS_UPLOAD_LOCATION/opnfv.properties \
53         gs://$GS_URL/latest.properties > /dev/null 2>&1
54 fi
55
56 gsutil ls $GS_UPLOAD_LOCATION > /dev/null 2>&1
57 if [[ $? -ne 0 ]]; then
58     echo "Problem while uploading artifacts!"
59     echo "Check log $WORKSPACE/gsutil.log on $NODE_NAME"
60     exit 1
61 fi
62 echo "Uploaded artifacts!"