Is there a Jenkins plugin that can do a group-artifact-version (GAV) search of my Nexus repo and list the results? I would like the results to be available on a parameterized build as a choice (a dropdown).
Jenkins build parameterized with a choice of versions of a Nexus artifact (all GAVs)
7.1k views Asked by bmcdonald AtThere are 3 answers
chose "Dynamic Choice Parameter" Plugin, and put the below code with your own host, groupId, artifactId.
we can use metadata API, you can use snapshots repo or release repo or public for both, just limit the last 5 versions.
def host="https://msnexus.xxx.com"
def groupId="com.xxx.cd".replaceAll("\\.", "/")
def artifactId="common-log"
def nexus_url="${host}/repository/public/${groupId}/${artifactId}/maven-metadata.xml"
def response=nexus_url.toURL().text
def metadata = new XmlParser().parseText(response)
metadata.versioning.versions.version.takeRight(5).collect({it.text()}).reverse()
same answer with a snapshot in https://stackoverflow.com/a/64831485/11411638
No need for custom Ruby scripts. There is now a dedicated plugin which does what you require: Maven Metadata Plugin for Jenkins CI server
Just mark "Parameterized Build" and "Add Parameter" of type "List Maven artifact versions":
- Name
MY_SNAPSHOT_JAR
- Repository Base URL (this one is tricky)
http://localhost/nexus/service/local/repositories/snapshots/content
Then add a shell command to wget/scp/etc, you can use the following variables resolved by plugin:
wget "$MY_SNAPSHOT_JAR_ARTIFACT_URL"
echo "$MY_SNAPSHOT_JAR_VERSION" - the version you selected in the dropdown or that was selected as part of an automated build
echo "$MY_SNAPSHOT_JAR_ARTIFACT_URL" - the full URL to the actual artifact selected. You can use something like "wget" to download that artifact and do something with it.
echo "$MY_SNAPSHOT_JAR_GROUP_ID" - echoes back your configuration
echo "$MY_SNAPSHOT_JAR_ARTIFACT_ID" - echoes back your configuration
echo "$MY_SNAPSHOT_JAR_CLASSIFIER" - echoes back your configuration
echo "$MY_SNAPSHOT_JAR_PACKAGING" - echoes back your configuration
Unfortunately you cannot ask about snapshot and release in the same dropdown list. A possible workaround is to add another parameter for MY_RELEASE_JAR (thus another dropdown list, somewhat confusing for a user). Another workaround is to have a separate job for release deployment.
I added a groovy script to a Dynamic Choice Parameter (See Jenkins Plugins)
Some hurdles were: