Thanks to the Link from @Yuri G.
and the hint from @lance-java about parsing the XML I was able to figure out a solution.
We're using gradle for the build, and I'm running this on Jenkins, I don't know if maven is installed.
I started with the Gradle Task from the link and then modified it to read the maven-metadata.xml
file in the folder. NOTE: we're using Artifactory not Nexus.
task getLatestSnapshotURL() {
doLast
{
def url = artifactoryURL + config.binaryRepository.snapshotUrl
def appBaseURL = String.format("%s/%s/%s/%s/", url.toString(),
config.groupId.replace('.', '/'),
config.artifactId, version)
.replace('null','')
def xmlUrl = appBaseURL + "maven-metadata.xml";
println('metadata.xml URL: ' + xmlUrl)
def ts = ''
def build = ''
try
{
def downloadXmlURL = new URL(xmlUrl)
def fStream = downloadXmlURL.openStream()
def slurper = new XmlSlurper().parse(fStream)
println(slurper)
println(XmlUtil.serialize(slurper))
def ver = slurper.versioning
println("versioning: " + ver)
println(XmlUtil.serialize(ver))
ts = ver.snapshot.timestamp.text()
build = ver.snapshot.buildNumber.text()
}
catch(Exception ex)
{
println("Unexpected Error getting Snapshot Version "
+ ex.getMessage() + "\n" + ex.getStackTrace());
}
println("ts: " + ts)
println("ts Type: " + ts.getClass())
println("build: " + build)
println("build Type: " + build.getClass())
def warUrl = appBaseURL + String.format("%s-%s-%s-%s.war",
config.artifactId,
version.replace("-SNAPSHOT", ''),
ts, build)
println('war URL: ' + warUrl)
try
{
def jarfile = new URL(warUrl)
def inStream = jarfile.openStream();
if (inStream != null)
{
println(String.format("%s:%s:%s", config.groupId,
config.artifactId, version)
+ " -> " + warUrl)
return
}
}
catch (Exception ignored) { }
}
}