summaryrefslogtreecommitdiffstats
path: root/jjb/kvmfornfv/kvmfornfv-upload-artifact.sh
blob: 327ea97e8575fb8bad9aa12cf161bb32accbfe20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
set -o errexit
set -o nounset

if [[ "$JOB_NAME" =~ (verify|merge|daily|weekly) ]]; then
    JOB_TYPE=${BASH_REMATCH[0]}
else
    echo "Unable to determine job type!"
    exit 1
fi

case "$JOB_TYPE" in
    verify)
        GS_UPLOAD_LOCATION="gs://artifacts.opnfv.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"
        echo "Removing outdated artifacts produced for the previous patch for the change $GERRIT_CHANGE_NUMBER"
        gsutil ls $GS_UPLOAD_LOCATION > /dev/null 2>&1 && gsutil rm -r $GS_UPLOAD_LOCATION
        echo "Uploading artifacts for the change $GERRIT_CHANGE_NUMBER. This could take some time..."
        ;;
    daily)
        echo "Uploading daily artifacts This could take some time..."
        OPNFV_ARTIFACT_VERSION=$(date -u +"%Y-%m-%d_%H-%M-%S")
        GS_UPLOAD_LOCATION="gs://$GS_URL/$OPNFV_ARTIFACT_VERSION"
        ;;
    *)
        echo "Artifact upload is not enabled for $JOB_TYPE jobs"
        exit 1
esac

gsutil cp -r $WORKSPACE/build_output/* $GS_UPLOAD_LOCATION > $WORKSPACE/gsutil.log 2>&1
gsutil -m setmeta -r \
    -h "Cache-Control:private, max-age=0, no-transform" \
    $GS_UPLOAD_LOCATION > /dev/null 2>&1

gsutil ls $GS_UPLOAD_LOCATION > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
    echo "Problem while uploading artifacts!"
    echo "Check log $WORKSPACE/gsutil.log on $NODE_NAME"
    exit 1
fi
echo "Uploaded artifacts!"