Update Global-jjb to master
[releng.git] / jjb / escalator / escalator-upload-artifact.sh
1 #!/bin/bash
2 echo "--------------------------------------------------------"
3 echo "This is escalator upload job!"
4 echo "--------------------------------------------------------"
5
6 set -o pipefail
7
8 # check if we built something
9 if [ -f $WORKSPACE/.noupload ]; then
10     echo "Nothing new to upload. Exiting."
11     /bin/rm -f $WORKSPACE/.noupload
12     exit 0
13 fi
14
15 # source the opnfv.properties to get ARTIFACT_VERSION
16 source $WORKSPACE/opnfv.properties
17
18 importkey () {
19 # clone releng repository
20 echo "Cloning releng repository..."
21 [ -d releng ] && rm -rf releng
22 git clone https://gerrit.opnfv.org/gerrit/releng $WORKSPACE/releng/ &> /dev/null
23 #this is where we import the siging key
24 if [ -f $WORKSPACE/releng/utils/gpg_import_key.sh ]; then
25   source $WORKSPACE/releng/utils/gpg_import_key.sh
26 fi
27 }
28
29 signtar () {
30 gpg2 -vvv --batch --yes --no-tty \
31   --default-key opnfv-helpdesk@rt.linuxfoundation.org  \
32   --passphrase besteffort \
33   --detach-sig $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.tar.gz
34
35 gsutil cp $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.tar.gz.sig gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.tar.gz.sig
36 echo "TAR signature Upload Complete!"
37 }
38
39 uploadtar () {
40 # log info to console
41 echo "Uploading $INSTALLER_TYPE artifact. This could take some time..."
42 echo
43
44 cd $WORKSPACE
45 # upload artifact and additional files to google storage
46 gsutil cp $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.tar.gz \
47     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.tar.gz > gsutil.tar.log 2>&1
48 gsutil cp $WORKSPACE/opnfv.properties \
49     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > gsutil.properties.log 2>&1
50 if [[ ! "$JOB_NAME" =~ (verify|merge) ]]; then
51     gsutil cp $WORKSPACE/opnfv.properties \
52     gs://$GS_URL/latest.properties > gsutil.latest.log 2>&1
53 elif [[ "$JOB_NAME" =~ "merge" ]]; then
54     echo "Uploaded Escalator TAR for a merged change"
55 fi
56
57 gsutil -m setmeta \
58     -h "Content-Type:text/html" \
59     -h "Cache-Control:private, max-age=0, no-transform" \
60     gs://$GS_URL/latest.properties \
61     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > /dev/null 2>&1
62
63 gsutil -m setmeta \
64     -h "Cache-Control:private, max-age=0, no-transform" \
65     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.tar.gz > /dev/null 2>&1
66
67 # disabled errexit due to gsutil setmeta complaints
68 #   BadRequestException: 400 Invalid argument
69 # check if we uploaded the file successfully to see if things are fine
70 gsutil ls gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.tar.gz > /dev/null 2>&1
71 if [[ $? -ne 0 ]]; then
72     echo "Problem while uploading artifact!"
73     echo "Check log $WORKSPACE/gsutil.bin.log on the machine where this build is done."
74     exit 1
75 fi
76
77 echo "Done!"
78 echo
79 echo "--------------------------------------------------------"
80 echo
81 echo "Artifact is available as http://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.tar.gz"
82 echo
83 echo "--------------------------------------------------------"
84 echo
85 }
86
87 importkey
88 signtar
89 uploadtar