show_me_the_money.jpg

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.

Show-Me-The-Money2.jpg

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.

Show-Me-The-Money3.jpg

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".

ShowMeTheMoney.png

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

DynamicChoiceParameter.png

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.

BuildStep.png

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'!

JerryMaquire.png

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.

Flow.png

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...)

Enjoy!!!

Yoram Michaeli - Tikal Knowledge