Skip to content

Uno Choice Dynamic Reference Parameter

Bruno P. Kinoshita edited this page May 19, 2014 · 4 revisions

This job parameter is similar to the Uno Choice Cascade Dynamic Choice Parameter. But it doesn't exactly provide a job parameter. Instead, it provides a reference for choosing the right parameters.

An example of use of this parameter might help. Image you are a researcher that have a Jenkins job that is triggered several times a day, and your job produces three graphs. Depending on what was plotted on these graphs, your next execution may need different parameters. Going back to the job screen, or having to look at somewhere else for the graphs can be time consuming (and boring). Thus this plug-in, that can add HTML elements with artifacts from your previous builds.

You will have to provide a Groovy Script that can be used to compose different elements. Namely:

  • An input text box (<input value="" >). The Groovy script must return a String.
  • An ordered list (<ol></ol>). The Groovy script must return a List.
  • An unordered list (<ul></ul>). The Groovy script must return a List.
  • Custom formatted HTML (you name it). The Groovy script must return a String (you can include any HTML tags here, e.g.: some <table>, or a <form> to another web site)
  • A simple image gallery (we will explain this one later)

Your Groovy script will three variables bound for it:

  • jenkinsProject -> The Jenkins Project object
  • jenkinsBuild -> The Jenkins Build object
  • artifacts -> List of archived artifacts of the last build

Let's use the following code as example:

int defaultBuild = 8;
import hudson.model.*
def choices=[]
def job = hudson.model.Hudson.instance.getItem("test003") 
def build = null

build=job.getBuildByNumber(defaultBuild)
env=[:] 
env= build.getEnvironment(TaskListener.NULL);
buildURL=env['BUILD_URL']
artifact=[]
   artifact= build.getArtifacts()
   artifact.each {
     println "$buildURL/artifact/$it"
     choices.add(buildURL + "artifact/$it")
   }  
println choices
return choices

What the script above does is given a build number, it will retrieve the artifacts from this build and will return them as a list.

Using an ordered list as element type we get the following.

If we switch the element type to Simple Image Gallery, here is the result.

This is a WIP, and will likely change parts of the UI and design