blob: 78da207b5aadbfc4412f0b27a75dcd45318a665c [file] [log] [blame]
Lusheng Ji5bc79f42017-08-29 14:20:46 +00001#!/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
22echo "running script: [$0] for module [$1] at stage [$2]"
23
24echo "=> Prepare environment "
Tony Hansen4b747742017-09-19 05:04:05 +000025env
Lusheng Ji5bc79f42017-08-29 14:20:46 +000026
Tony Hansen4b747742017-09-19 05:04:05 +000027# This is the base for where "deploy" will upload
28# MVN_NEXUSPROXY is set in the pom.xml
29REPO=$MVN_NEXUSPROXY/content/sites/raw/$MVN_PROJECT_GROUPID
30
31TIMESTAMP=$(date +%C%y%m%dT%H%M%S)
Lusheng Ji5bc79f42017-08-29 14:20:46 +000032export BUILD_NUMBER="${TIMESTAMP}"
33
Tony Hansen4b747742017-09-19 05:04:05 +000034# expected environment variables
Lusheng Ji5bc79f42017-08-29 14:20:46 +000035if [ -z "${MVN_NEXUSPROXY}" ]; then
36 echo "MVN_NEXUSPROXY environment variable not set. Cannot proceed"
37 exit
38fi
39MVN_NEXUSPROXY_HOST=$(echo "$MVN_NEXUSPROXY" |cut -f3 -d'/' | cut -f1 -d':')
Tony Hansen4b747742017-09-19 05:04:05 +000040echo "=> Nexus Proxy at $MVN_NEXUSPROXY_HOST, $MVN_NEXUSPROXY"
Lusheng Ji5bc79f42017-08-29 14:20:46 +000041
42# use the version text detect which phase we are in in LF CICD process: verify, merge, or (daily) release
43
Tony Hansen4b747742017-09-19 05:04:05 +000044# mvn phase in life cycle
Lusheng Ji5bc79f42017-08-29 14:20:46 +000045MVN_PHASE="$2"
Tony Hansen4b747742017-09-19 05:04:05 +000046shift 2
Lusheng Ji5bc79f42017-08-29 14:20:46 +000047
48case $MVN_PHASE in
49clean)
50 echo "==> clean phase script"
Tony Hansen4b747742017-09-19 05:04:05 +000051 if [ -f makefile -o -f Makefile ];then make clean; else :; fi
Lusheng Ji5bc79f42017-08-29 14:20:46 +000052 ;;
53generate-sources)
54 echo "==> generate-sources phase script"
Tony Hansen4b747742017-09-19 05:04:05 +000055 if [ -f makefile -o -f Makefile ];then make generate-sources; else :; fi
Lusheng Ji5bc79f42017-08-29 14:20:46 +000056 ;;
57compile)
58 echo "==> compile phase script"
Tony Hansen4b747742017-09-19 05:04:05 +000059 if [ -f makefile -o -f Makefile ];then make compile; else :; fi
Lusheng Ji5bc79f42017-08-29 14:20:46 +000060 ;;
61test)
62 echo "==> test phase script"
Tony Hansen4b747742017-09-19 05:04:05 +000063 if [ -f makefile -o -f Makefile ];then make test; else :; fi
Lusheng Ji5bc79f42017-08-29 14:20:46 +000064 ;;
65package)
66 echo "==> package phase script"
Tony Hansen4b747742017-09-19 05:04:05 +000067 if [ -f makefile -o -f Makefile ];then make package; else :; fi
Lusheng Ji5bc79f42017-08-29 14:20:46 +000068 ;;
69install)
70 echo "==> install phase script"
Tony Hansen4b747742017-09-19 05:04:05 +000071 if [ -f makefile -o -f Makefile ];then make install; else :; fi
Lusheng Ji5bc79f42017-08-29 14:20:46 +000072 ;;
73deploy)
74 echo "==> deploy phase script"
Tony Hansen4b747742017-09-19 05:04:05 +000075 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 Ji5bc79f42017-08-29 14:20:46 +0000101 ;;
102*)
103 echo "==> unprocessed phase"
104 ;;
105esac
106