Make sure that jjb-cleanup.sh allows unbound vars
[releng/global-jjb.git] / shell / deploy-maven-file.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 # This script publishes packages (rpms/debs) or any file to Nexus hosted
13 # maven2 repository.
14 #
15 # $MAVEN_REPO_URL     :  Provided by a job parameter.
16 #                        The calling job can set $NEXUS_URL path or local
17 #                        directory to stage files. ex:
18 #                         -Durl="${NEXUS_URL}/content/repositories/$REPO_ID"
19 #                         -Durl="file://$WORKSPACE/m2repo"
20 # $REPO_ID            :  Provided by a job parameter.
21 #                        A repository ID represents the repository.
22 # $GROUP_ID           :  Provided by a job parameter.
23 #                        A group ID represents a nexus group.
24 # $UPLOAD_FILES_PATH   :  Provided by a job parameter.
25 #                        The directory contains one or more artifacts.
26
27 echo "---> deploy-maven-file.sh"
28
29 # DO NOT enable -u because $MAVEN_PARAMS and $MAVEN_OPTIONS could be unbound.
30 # Ensure we fail the job if any steps fail.
31 set -e -o pipefail
32 set +u
33
34 export MAVEN_OPTIONS
35 export MAVEN_PARAMS
36
37 DEPLOY_LOG="$WORKSPACE/archives/deploy-maven-file.log"
38 mkdir -p "$WORKSPACE/archives"
39
40 while IFS="" read -r file
41 do
42     file_size=$(stat --printf="%s" "${file}")
43     echo "Deploy ${file##*/} with ${file_size} bytes."
44     lftools deploy maven-file "$MAVEN_REPO_URL" \
45                               "$REPO_ID" \
46                               "$file" \
47                               -b "$MVN" \
48                               -g "$GROUP_ID" \
49                               -p "$MAVEN_OPTIONS $MAVEN_PARAMS" \
50                               |& tee "$DEPLOY_LOG"
51 done < <(find "$UPLOAD_FILES_PATH" -xtype f -name "*")