-
Notifications
You must be signed in to change notification settings - Fork 1
/
deployJarFromNexus.sh
executable file
·49 lines (38 loc) · 1.79 KB
/
deployJarFromNexus.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# This is a shell script to deploy a JAR from a nexus repository.
# The script takes parameters to customise the name and profile to use.
# Usage: deployJarFromNexus.sh nameOfMavenArtifact springProfile
#Define variables
NAME=$1;
PROFILE=$2
#Create temporary working directory
rm -rf tmp_deployment/
mkdir tmp_deployment
cd tmp_deployment
#Define constants
#This variable should match the group id in maven as a directory path.
PACKAGE="/de/davelee/mypackage"
#This variable should contain the base url to your Nexus Installation.
NEXUS_URL="http://localhost:8002"
#Get the maven metadata file
echo "$NEXUS_URL"/repository/maven-snapshots/"$PACKAGE"/"$1"/maven-metadata.xml
curl -o versions.xml "$NEXUS_URL"/repository/maven-snapshots/"$PACKAGE"/"$1"/maven-metadata.xml
#Retrieve the latest version into a variable.
BASE_VERSION=$(xmllint --xpath '/metadata/versioning/latest/text()' versions.xml)
echo 'Base:'"$BASE_VERSION";
if [[ -z "$BASE_VERSION" ]]; then
BASE_VERSION=$(xmllint --xpath '/metadata/versioning/versions/version/text()' versions.xml)
fi
echo 'Base:'$BASE_VERSION;
#Get the next maven metdata file.
curl -o timestamps.xml "$NEXUS_URL"/repository/maven-snapshots/"$PACKAGE"/"$1"/"$BASE_VERSION"/maven-metadata.xml
#Retrieve the snapshot timestamp.
SNAPSHOT_TIMESTAMP=$(xmllint --xpath '/metadata/versioning/snapshotVersions/snapshotVersion[1]/value/text()' timestamps.xml)
#Download the jar file.
echo "$NEXUS_URL"/repository/maven-snapshots/"$PACKAGE"/"$1"/"$BASE_VERSION"/"$NAME"-"$SNAPSHOT_TIMESTAMP".jar
curl -o "$NAME".jar "$NEXUS_URL"/repository/maven-snapshots/"$PACKAGE"/"$1"/"$BASE_VERSION"/"$NAME"-"$SNAPSHOT_TIMESTAMP".jar
#Delete the versions and timestamps files.
#rm timestamps.xml
#rm versions.xml
#Start jar file.
java -jar -Dspring.profiles.active="$PROFILE" "$NAME".jar