How to populate Choice Parameter with artifact information using Nexus REST API?

Article ID:217958928
2 minute readKnowledge base


  • I would like to populate a Choice Parameter drop-down with artifact information from Nexus, using the Nexus REST API. This is an alternative approach to using the Repository Connector Plugin. Some customers have reported having issues using this plugin. I would investigate using this plugin first before reading on.

  • Optionally, Id like to use the Choice selection in Pipeline.


  • CloudBees Jenkins Enterprise

  • Pipeline (Optional)

  • Nexus REST API

  • Extensible Choice Parameter Plugin

  • Repository Connector Plugin (Alternative)


First, add the Extensible Choice and select "System Groovy Choice Parameter" - This build is parameterized - Extensible Choice - System Groovy Choice Parameter

Now lets focus on the Nexus REST API query.

The query can be broken up into the following pieces:


Modify these ${} pieces to suit your needs.

For example - will return artifact information for group id jboss, artifact id jboss-j2ee and type jar, from the JBoss Nexus Repository You can test the query in your browser to see the XML results returned by the API.

Now we are going to use some simple Groovy to query the API using the HTTP query we just described, extract the results and populate the drop-down. The code goes in the Groovy System Script field that the System Groovy Choice Parameter provides.

The following example creates a drop-down list of artifact versions:

def xml = "".toURL().text

def root = new XmlParser().parseText(xml)

return {

To explain this in more detail:

The first line defines and runs the HTTP query, saving the XML results as text.

The second line uses Groovy’s built in XmlParser to parse the XML.

The third line traverses the XML, collecting the artifact version from each artifact, finally calling return which populates the drop-down with the resulting collection.

The following example extends on the first, creating a drop-down list of artifacts, each item containing group id, artifact id and version, formatted using colon (:) separation:

def xml = "".toURL().text

def root = new XmlParser().parseText(xml)

return {

Pipeline Integration (Optional)

Let’s assume that when setting up a new parameter using the Extensible Choice Parameter Plugin that you gave the parameter you created the Name test. This name is important for referencing the drop-down value selected in your Pipeline.

Below is a usage example:

node {
    // example simply prints the drop-down value selected when triggering the build.
    echo "value ${test}"

Below is an advanced usage example, putting everything together in order to download an artifact to the current directory.

Imagine in this example that test holds the artifact version value 4.2.3.GA:

node {
    sh "curl -O${test}/jboss-j2ee-${test}.jar"