liamfallon | 6eda973 | 2021-03-23 11:57:00 +0000 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | set -o errexit |
| 3 | set -o nounset |
| 4 | set -o pipefail |
| 5 | |
| 6 | cd $WORKSPACE |
| 7 | echo "Info: Update Java alternatives" |
| 8 | echo "----------------------------------------------------" |
| 9 | sudo /usr/bin/update-alternatives --install /usr/bin/java java "${JAVA_HOME}/bin/java" 1 |
| 10 | sudo /usr/bin/update-alternatives --install /usr/bin/javac javac "${JAVA_HOME}/bin/javac" 1 |
| 11 | sudo /usr/bin/update-alternatives --install /usr/bin/javadoc javadoc "${JAVA_HOME}/bin/javadoc" 1 |
| 12 | sudo /usr/bin/update-alternatives --install /usr/bin/jconsole jconsole "${JAVA_HOME}/bin/jconsole" 1 |
| 13 | sudo /usr/bin/update-alternatives --install /usr/lib/jvm/java-openjdk java_sdk_openjdk "${JAVA_HOME}" 1 |
| 14 | sudo /usr/bin/update-alternatives --set java "${JAVA_HOME}/bin/java" |
| 15 | sudo /usr/bin/update-alternatives --set javac "${JAVA_HOME}/bin/javac" |
| 16 | sudo /usr/bin/update-alternatives --set javadoc "${JAVA_HOME}/bin/javadoc" |
| 17 | sudo /usr/bin/update-alternatives --set jconsole "${JAVA_HOME}/bin/jconsole" |
| 18 | sudo /usr/bin/update-alternatives --set java_sdk_openjdk "${JAVA_HOME}" |
| 19 | echo "Info: Java version" |
| 20 | echo "----------------------------------------------------" |
| 21 | echo -e "\tJava version: $(java -version 2>&1 | head -n 1)" |
| 22 | echo -e "\tJava compiler version: $(javac -version)" |
| 23 | echo -e "\tJAVA_HOME set to: ${JAVA_HOME}" |
| 24 | echo "----------------------------------------------------" |
| 25 | echo "Downloading Maven $MVN_VERSION from $MVN_URL" |
| 26 | wget -q $MVN_URL && unzip -qq apache-maven-${MVN_VERSION}-bin.zip |
| 27 | echo "Info: Maven version" |
| 28 | echo "----------------------------------------------------" |
| 29 | $MVN -version |
| 30 | echo "----------------------------------------------------" |
| 31 | echo "Downloading ONAP Maven XML for build process from oparent repo" |
| 32 | echo "----------------------------------------------------" |
| 33 | git clone "https://git.onap.org/oparent" $WORKSPACE/oparent |
| 34 | cd $WORKSPACE/oparent |
| 35 | # Check if a commitid parameter is given to specify a version of |
| 36 | # oparent repository to checkout. If commitid is not provided, the |
| 37 | # latest master version is used as default for backward |
| 38 | # compatibility for existing ONAP jobs. |
| 39 | set +o nounset |
| 40 | if [[ -v ${MVN_SETTINGS_XML_VERSION} ]]; then |
| 41 | git checkout "${MVN_SETTINGS_XML_VERSION}" |
| 42 | fi |
| 43 | set -o nounset |
| 44 | |
| 45 | # if MVN_PARAMS set then use them otherwise default to "" |
| 46 | LOCAL_MVN_PARAMS="" |
| 47 | set +o nounset |
| 48 | if [[ -n ${MVN_PARAMS} ]]; then |
| 49 | LOCAL_MVN_PARAMS=${MVN_PARAMS} |
| 50 | fi |
| 51 | set -o nounset |
| 52 | |
| 53 | # Copy Onap maven settings.xml to Jenkins home directory |
| 54 | if [ ! -d /home/jenkins/.m2 ]; then |
| 55 | mkdir -p /home/jenkins/.m2/ |
| 56 | fi |
| 57 | cp settings.xml /home/jenkins/.m2/settings.xml |
| 58 | cd $WORKSPACE |
| 59 | |
| 60 | POMFILE="-f $WORKSPACE/pom.xml" |
| 61 | set +o nounset |
| 62 | if [[ -n ${SUBDIRECTORY} ]]; then |
| 63 | POMFILE="-f $WORKSPACE/$SUBDIRECTORY/pom.xml" |
| 64 | echo "Setting pom.xml to use to $POMFILE" |
| 65 | fi |
| 66 | set -o nounset |
| 67 | |
| 68 | echo "----------------------------------------------------" |
| 69 | echo "Proceeding with unit test" |
| 70 | echo "----------------------------------------------------" |
| 71 | $MVN clean install -U -B $POMFILE -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn $LOCAL_MVN_PARAMS |