kvmfornfv: Remove artifacts created for the previous patch of the same change
[releng.git] / jjb / kvmfornfv / kvmfornfv-upload-artifact.sh
1 #!/bin/bash
2 set -o errexit
3 set -o nounset
4 set -o pipefail
5
6 if [[ "$JOB_NAME" =~ (verify|merge|daily|weekly) ]]; then
7     JOB_TYPE=${BASH_REMATCH[0]}
8 else
9     echo "Unable to determine job type!"
10     exit 1
11 fi
12
13 case "$JOB_TYPE" in
14     verify)
15         echo "Uploading artifacts for the change $GERRIT_CHANGE_NUMBER. This could take some time..."
16         GS_UPLOAD_LOCATION="gs://artifacts.opnfv.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"
17         echo "Removing artifacts produced for the previous patch for the change $GERRIT_CHANGE_NUMBER"
18         gsutil rm -r $GS_UPLOAD_LOCATION
19         ;;
20     daily)
21         echo "Uploding 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 gsutil cp -r $WORKSPACE/build_output/* $GS_UPLOAD_LOCATION > $WORKSPACE/gsutil.log 2>&1
31 gsutil -m setmeta -r \
32     -h "Cache-Control:private, max-age=0, no-transform" \
33     $GS_UPLOAD_LOCATION > /dev/null 2>&1
34
35 gsutil ls $GS_UPLOAD_LOCATION > /dev/null 2>&1
36 if [[ $? -ne 0 ]]; then
37     echo "Problem while uploading artifacts!"
38     echo "Check log $WORKSPACE/gsutil.log on $NODE_NAME"
39     exit 1
40 fi
41 echo "Uploaded artifacts!"