Chore: Upgrade Jenkins-job-builder to 6.3.0
[releng/global-jjb.git] / shell / maven-fetch-metadata.sh
index 26b2c96..4f719e3 100644 (file)
@@ -8,19 +8,30 @@
 # which accompanies this distribution, and is available at
 # http://www.eclipse.org/legal/epl-v10.html
 ##############################################################################
-
+echo "---> maven-fetch-metadata.sh"
 # Uses wget to fetch a project's maven-metadata.xml files from a Maven repository.
 
+# Check for "-f" maven param, indicating a change in pom location.
+pom_path="pom.xml"
+file_path=$(echo "$MAVEN_PARAMS" | grep -Eo "\-f \S+" | awk '{ print $2 }')
+if [ -n "$file_path" ]; then
+    if [ -d "$file_path" ]; then
+        pom_path="$file_path/pom.xml"
+    else
+        pom_path="$file_path"
+    fi
+fi
+
 # Ensure we fail the job if any steps fail.
 set -xeu -o pipefail
 
 project=$(xmlstarlet sel \
     -N "x=http://maven.apache.org/POM/4.0.0" -t \
     --if "/x:project/x:groupId" \
-      -v "/x:project/x:groupId" \
+        -v "/x:project/x:groupId" \
     --elif "/x:project/x:parent/x:groupId" \
-      -v "/x:project/x:parent/x:groupId" \
-    --else -o "" pom.xml)
+        -v "/x:project/x:parent/x:groupId" \
+    --else -o "" "$pom_path")
 project_path="${project//.//}"
 
 mkdir -p "$WORKSPACE/m2repo/$project_path"