Chore: Upgrade Jenkins-job-builder to 6.3.0
[releng/global-jjb.git] / shell / maven-deploy.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 # Upload the snapshot files to a snapshot repo.
12 #
13 # Requires the existance of $WORKSPACE/m2repo and $WORKSPACE/m2repo-backup to
14 # compare if maven metadata files have changed. Unchanged files are then
15 # removed from $WORKSPACE/m2repo before uploading to the snapshot repo.
16 echo "---> maven-deploy.sh"
17
18 # Ensure we fail the job if any steps fail.
19 set -eu -o pipefail
20
21 m2repo_dir="$WORKSPACE/m2repo"
22 nexus_repo_url="$NEXUS_URL/content/repositories/$NEXUS_REPO"
23
24 echo "-----> Remove metadata files that were not updated"
25 set +e  # Temporarily disable to run diff command.
26 mapfile -t metadata_files <<< "$(diff -s -r "$m2repo_dir" "$WORKSPACE/m2repo-backup" \
27     | grep 'Files .* and .* are identical' \
28     | awk '{print $2}')"
29 set -e  # Re-enable.
30
31 set +u  # $metadata_files could be unbound if project is new.
32 if [ -n "${metadata_files[*]}" ]; then
33     for i in "${metadata_files[@]}"; do
34         echo "Removing unmodified file $i"
35         rm "$i"*
36     done
37 fi
38 set -u  # Re-enable.
39
40 find "$m2repo_dir" -type d -empty -delete
41
42 echo "-----> Install lftools"
43 # shellcheck disable=SC1090
44 . ~/lf-env.sh
45
46 lf-activate-venv --python python3 lftools
47
48 echo "-----> Upload files to Nexus"
49 lftools deploy nexus -s "$nexus_repo_url" "$m2repo_dir"