Skip to content

Example_UC_helper_GetBuildsByNumAsMap

Ioannis K. Moutsatsos edited this page Oct 13, 2020 · 9 revisions

Select from a defined range of a Jenkins project builds

Motivation

We want to select artifacts from a particular job build. We will use 2 Active Choice parameters such that in the first one the user selects the job build (from a list of human readable build labels) and the second one updates dynamically to display the artifacts of the selected build.

This example explains how we can retrieve builds in a specified range of a job, and display them as human readable list of options to the user.

The first Active Choice parameter uses the UC_helper_GetBuildsByNumAsMap scriptlet to display a user-defined range of project builds.

Note that the Active Choices plugin was originally known as the Uno-Choice plugin, a name that is used in this page.

Configuration

We start by adding a new UC-Dynamic Choice (Active Choices) Parameter to the project.

In this example we call this parameter SOURCE_BUILD We specify the 'job' and the returned 'build range' with three scriptlet parameters.

  1. vSearchSpace : this is the name of one (or more) jobs that we want to retrieve a range of builds from
  2. f: (for first) specifies the start range number of build to be returned
  3. l: (for last) the end range number of builds to be returned. If no value is provided all builds starting with 'f' will be included

Note that we can specify a combined job search space with more than one job names if this is required by your project. In this case we supply a comma separated list of job names for the vSearchSpace parameter .

By default, the range map only includes builds tagged with the SUCCESS status

Parameter Display

When the Active Choice parameter is rendered in the build form it displays a list of successful builds belonging to the specified job and satisfying the build range criteria.

Note how the returned numbers in this range are not consecutive as not all of the builds were successful.

Build Parameter

Note that when the user selects one of the SOURCE_BUILD parameter options and submits a build, the build is actually submitted with a parameter value representing the key of the selected option.

For example:

The scriptlet allows you to customize the display of the parameter choice options while maintaining an internally standardize way to represent the parameter value submitted to the build.