Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # ================================================================================ |
| 4 | # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. |
| 5 | # ================================================================================ |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # ============LICENSE_END========================================================= |
| 18 | # |
| 19 | # ECOMP is a trademark and service mark of AT&T Intellectual Property. |
| 20 | |
| 21 | |
| 22 | echo "running script: [$0] for module [$1] at stage [$2]" |
| 23 | |
| 24 | echo "=> Prepare environment " |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 25 | env |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 26 | |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 27 | # This is the base for where "deploy" will upload |
| 28 | # MVN_NEXUSPROXY is set in the pom.xml |
| 29 | REPO=$MVN_NEXUSPROXY/content/sites/raw/$MVN_PROJECT_GROUPID |
| 30 | |
| 31 | TIMESTAMP=$(date +%C%y%m%dT%H%M%S) |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 32 | export BUILD_NUMBER="${TIMESTAMP}" |
| 33 | |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 34 | # expected environment variables |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 35 | if [ -z "${MVN_NEXUSPROXY}" ]; then |
| 36 | echo "MVN_NEXUSPROXY environment variable not set. Cannot proceed" |
| 37 | exit |
| 38 | fi |
| 39 | MVN_NEXUSPROXY_HOST=$(echo "$MVN_NEXUSPROXY" |cut -f3 -d'/' | cut -f1 -d':') |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 40 | echo "=> Nexus Proxy at $MVN_NEXUSPROXY_HOST, $MVN_NEXUSPROXY" |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 41 | |
| 42 | # use the version text detect which phase we are in in LF CICD process: verify, merge, or (daily) release |
| 43 | |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 44 | # mvn phase in life cycle |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 45 | MVN_PHASE="$2" |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 46 | shift 2 |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 47 | |
| 48 | case $MVN_PHASE in |
| 49 | clean) |
| 50 | echo "==> clean phase script" |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 51 | if [ -f makefile -o -f Makefile ];then make clean; else :; fi |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 52 | ;; |
| 53 | generate-sources) |
| 54 | echo "==> generate-sources phase script" |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 55 | if [ -f makefile -o -f Makefile ];then make generate-sources; else :; fi |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 56 | ;; |
| 57 | compile) |
| 58 | echo "==> compile phase script" |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 59 | if [ -f makefile -o -f Makefile ];then make compile; else :; fi |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 60 | ;; |
| 61 | test) |
| 62 | echo "==> test phase script" |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 63 | if [ -f makefile -o -f Makefile ];then make test; else :; fi |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 64 | ;; |
| 65 | package) |
| 66 | echo "==> package phase script" |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 67 | if [ -f makefile -o -f Makefile ];then make package; else :; fi |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 68 | ;; |
| 69 | install) |
| 70 | echo "==> install phase script" |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 71 | if [ -f makefile -o -f Makefile ];then make install; else :; fi |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 72 | ;; |
| 73 | deploy) |
| 74 | echo "==> deploy phase script" |
Tony Hansen | 4b74774 | 2017-09-19 05:04:05 +0000 | [diff] [blame^] | 75 | if [ -f makefile -o -f Makefile ];then make deploy |
| 76 | else |
| 77 | # Upload all files (listed as additional deployment arguments) to Nexus |
| 78 | set -e -x |
| 79 | function setnetrc { |
| 80 | # Turn off -x so won't leak the credentials |
| 81 | set +x |
| 82 | hostport=$(echo $1 | cut -f3 -d /) |
| 83 | host=$(echo $hostport | cut -f1 -d:) |
| 84 | settings=${SETTINGS_FILE:-$HOME/.m2/settings.xml} |
| 85 | echo machine $host login $(xpath -q -e "//servers/server[id='$MVN_SERVER_ID']/username/text()" $settings) password $(xpath -q -e "//servers/server[id='$MVN_SERVER_ID']/password/text()" $settings) >$HOME/.netrc |
| 86 | chmod 600 $HOME/.netrc |
| 87 | set -x |
| 88 | } |
| 89 | function putraw { |
| 90 | curl -X PUT -H "Content-Type: $3" --netrc --upload-file $1 --url $REPO/$2 |
| 91 | } |
| 92 | setnetrc $REPO |
| 93 | |
| 94 | # additional |
| 95 | for artifact |
| 96 | do |
| 97 | putraw $artifact artifacts/$artifact application/data |
| 98 | done |
| 99 | set +e +x |
| 100 | fi |
Lusheng Ji | 5bc79f4 | 2017-08-29 14:20:46 +0000 | [diff] [blame] | 101 | ;; |
| 102 | *) |
| 103 | echo "==> unprocessed phase" |
| 104 | ;; |
| 105 | esac |
| 106 | |