Builds and archives uds artifacts
[infra/cicd.git] / jjb / onap / uds / scripts / maven-build.sh
1 #!/bin/bash
2 # ============LICENSE_START=======================================================
3 #  Copyright (C) 2020 The Nordix Foundation. All rights reserved.
4 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
19
20 set -o errexit
21 set -o nounset
22 set -o pipefail
23
24 cd $WORKSPACE
25
26 echo "----------------------------------------------------"
27 echo "Info: Java version"
28 echo "----------------------------------------------------"
29 java -version
30
31 echo "----------------------------------------------------"
32 echo "Info: Downloading Maven $MVN_VERSION from $MVN_URL"
33 echo "----------------------------------------------------"
34 wget -q $MVN_URL && unzip -qqn apache-maven-$MVN_VERSION-bin.zip
35
36 echo "----------------------------------------------------"
37 echo "Info: Maven version"
38 echo "----------------------------------------------------"
39 $MVN -version
40
41 echo "----------------------------------------------------"
42 echo "Info: Downloading ONAP Maven XML for build process"
43 echo "----------------------------------------------------"
44 git clone "https://git.onap.org/oparent" $WORKSPACE/oparent
45 cd $WORKSPACE/oparent
46 # Check if a commitid parameter is given to specify a version of
47 # oparent repository to checkout
48 if [[ -v MVN_SETTINGS_XML_VERSION ]]; then
49   git checkout $MVN_SETTINGS_XML_VERSION
50 fi
51 # Copy Onap maven settings.xml to Jenkins home directory
52 mkdir -p /home/jenkins/.m2/
53 cp settings.xml /home/jenkins/.m2/settings.xml
54 cd $WORKSPACE
55
56
57 echo "----------------------------------------------------"
58 echo "Info: Ensuring Docker is running"
59 echo "----------------------------------------------------"
60 # If docker daemon isnt up attempt to start it
61 if ! docker info;
62 then
63   systemctl start docker
64 fi
65
66 # Turn PROJECTS and PROJECT_DIRECTORIES paramter strings into arrays
67 # Required in order to loop through them
68 PROJECTS=(`echo $PROJECTS | sed 's/,/\n/g'`)
69 PROJECT_DIRECTORIES=(`echo $PROJECT_DIRECTORIES | sed 's/,/\n/g'`)
70
71 # Find and store array lenth of one of the arrays
72 ARRAY_LENGTH=$(echo ${#PROJECTS[@]})
73 # Take 1 of the array length for the loop
74 ((ARRAY_LENGTH--))
75
76 # For each project source repository do a maven build
77 # e.g. maven clean install -DskipTests -Pdocker
78 for i in $(seq 0 $ARRAY_LENGTH)
79 do
80   echo "----------------------------------------------------"
81   echo "INFO: Maven Build for ${PROJECTS[$i]}"
82   echo "----------------------------------------------------"
83   $MVN clean install $MVN_PARAMS -f ${PROJECT_DIRECTORIES[$i]}
84 done