kvmfornfv: Attempt removing outdated artifacts only if the exist
[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         echo "Uploading artifacts for the change $GERRIT_CHANGE_NUMBER. This could take some time..."
15         GS_UPLOAD_LOCATION="gs://artifacts.opnfv.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"
16         echo "Removing 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         ;;
19     daily)
20         echo "Uploding 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         ;;
24     *)
25         echo "Artifact upload is not enabled for $JOB_TYPE jobs"
26         exit 1
27 esac
28
29 gsutil cp -r $WORKSPACE/build_output/* $GS_UPLOAD_LOCATION > $WORKSPACE/gsutil.log 2>&1
30 gsutil -m setmeta -r \
31     -h "Cache-Control:private, max-age=0, no-transform" \
32     $GS_UPLOAD_LOCATION > /dev/null 2>&1
33
34 gsutil ls $GS_UPLOAD_LOCATION > /dev/null 2>&1
35 if [[ $? -ne 0 ]]; then
36     echo "Problem while uploading artifacts!"
37     echo "Check log $WORKSPACE/gsutil.log on $NODE_NAME"
38     exit 1
39 fi
40 echo "Uploaded artifacts!"