Chore: Upgrade Jenkins-job-builder to 6.3.0
[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 # shellcheck disable=SC1090
35 . ~/lf-env.sh
36
37 lf-activate-venv --python python3 lftools
38
39 export MAVEN_OPTIONS
40 export MAVEN_PARAMS
41
42 DEPLOY_LOG="$WORKSPACE/archives/deploy-maven-file.log"
43 mkdir -p "$WORKSPACE/archives"
44
45 while IFS="" read -r file; do
46     file_size=$(stat --printf="%s" "${file}")
47     echo "Deploy ${file##*/} with ${file_size} bytes."
48     lftools deploy maven-file "$MAVEN_REPO_URL" \
49                                 "$REPO_ID" \
50                                 "$file" \
51                                 -b "$MVN" \
52                                 -g "$GROUP_ID" \
53                                 -p "$MAVEN_OPTIONS $MAVEN_PARAMS" \
54                                 |& tee "$DEPLOY_LOG"
55 done < <(find "$UPLOAD_FILES_PATH" -xtype f -name "*")