"Show Me The Money!" - running a Jenkins job multiple times on multiple sets of arguments


The Challenge

One of Tikal’s customer (one of many customers!), that have a CI-test Jenkins job that:

  • Includes 2 arguments
  • Each argument is a selected-file-path from a filtered-folders

I’ve been asked to provide a wrapping job (a nightly build job) that runs the CI-test job for all the combinations of files from those 2 filtered-folders.


Considered leads toward a solution

The first option I’ve considered, based on past experience and suggestions from my team-mates, was to use the Matrix Project Plugin. But after many failed-tries and considering that the files-paths arguments are dynamic ones (built using a Groovy script) and the obstacle to connect the Groovy-Axis (see: Jenkins Groovy Axis Plugin) to a triggered-job as a post-build step, I’ve decided to switch to a different option.

The selected option - which worked for me - were to use Extended Choice Parameter plugin and Build Flow Plugin.


Detailed description of the solution using a simple example

The example test-job

First, for the example, I’ve built the test job that gets 2 arguments of selected file-paths based on a folder that contains 2 types of text files:

  • Files named with country-name which contains the matching currencies for that country.
  • Files named with currency-name which contains the matching countries that uses that currency.

The content of those files leaded me to call the Jenkins job - that dump the content of those files - “Show Me The Money”.


The definition of the arguments used the Dynamic Parameter Plug-in as such:


The groovy filter (as used for the other arugment as well and for all the arugments in this example - including those in the wrapping job - were the following:

list = []
new File("/opt/input").eachDirRecurse() { dir ->
     dir.eachFileMatch(~/.*.country/) { file ->
list << file.getPath()
return list

Same goes for the CurrencyFile argument (filtered for the .currency files).

And the build-step in the example is a simple dump of the content of the arguments files.


The wrapping job (for nightly build)

First of all, I’ve created a new job called ‘JerryMaguire’ (the name of the film that includes that famous quote ‘Show Me The Money!”). The job must be of type ‘Build Flow’!


Next, I’ve added 2 arguments typed ‘Extended Choice Parameter’ which supports multiple selected values (since we want to run the test-job for all the matching-files in the folder) and supports also selecting all the values in the list by default (so that when running as nightly build, all the files-paths will be selected).

ExtendedChoiceParameter.png SourceForValue.png SourceForDefaultValue.png

Same goes for the currenciesFiles argument.

And finally, I’ve defined the build flow step, which is a 2-dimentional loop over all the combinations of the 2-files-paths and activating the test-job for each of those combinations.


def countries = params['countryFiles'].split(',')
def currencies = params['currenciesFiles'].split(',')
for (country in countries ) {
    for (currency in currencies ) {
         build("ShowMeTheMoney", CountryFile: country, CurrencyFile: currency)

In addition I’ve set the trigger of the build to run once-a-day - by default it will select all the files it finds in the folder(s) and will run on all the combinations of it.

(Click the video below and…)


Yoram Michaeli - Tikal Knowledge

Thank you for your interest!

We will contact you as soon as possible.

Want to Know More?

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com
Thank you for your interest!

We will contact you as soon as possible.

Let's talk

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com