Passing variables from jenkins to katalon scripts

Yes, it is possible to do it.
Let’s make an example, we’d like to have possibility to choose in jenkins on which test enviroment test will run.

  1. let’s make test data csv file (enviroment.csv) like this →
    envstart;yourenviroment;envstop
  2. add this file to your ‘data files’ in katalon: “use first row as header” must be unchecked, choose “semicolon” as separator
  3. of course you have to declare variable in your test script and make some logic to choose enviroment, i.e.:
    def tablewithmytestdata = TestDataFactory.findTestData("Data Files/nameofyourdatafile") def chooseenviroment = tablewithmytestdata.getValue(2, 1) if (chooseenviroment == 'TEST1') { WebUI.navigateToUrl('http://urlofyourtest1enviroment') } else if (chooseenviroment == 'TEST2') { WebUI.navigateToUrl('http://urlofyourtest2enviroment') } else { WebUI.navigateToUrl('http://urlofyourotherenviroment') }
  4. ok, everything is done in katalon already, now it’s time to handle test data in jenkins. First, in your jenkins project check “this build is parametrized”, next add ‘choose list’ parameter, for example with name “ChooseYourEnviroment” and values: TEST1, TEST2, OTHERENV,
  5. ok, but how to pass chosen parameter to your katalon data file? you have 2 options:
  1. in our example i’ll use fnr.exe. In jenkins’ build section choose “execute windows batch command” and put a command →
    “C:\catalogwithyourfnr\fnr.exe” --cl --dir “C:\catalogwhereyourenviromentcsvfileis” --fileMask “enviroment.csv” --useRegEx --find “envstart;(.*);envstop” --replace “envstart;%ChooseYourEnviroment%;envstop”
    here is your CMD generated with katalon to run your script

Ok, what it does? It just changes the string in your csv file for the enviroment you chose in jenkins. Next, katalon script reads this file and set ‘chooseenviroment’ variable with your chosen value.
Logic in katalon script makes the rest of job.
Hope this helps.

PS.
VERY, VERY IMPORTANT!
don’t use fart or fnr in order to modify your groovy scripts. That will break that script. Katalon groovy scripts MAY NOT be modified outside katalon (in notepad for example). I think some relations are broken if you do that.
Use fart/fnr to modify ONLY testdata files.

PPS.
of course if you need, you can run fnr/fart commands also directly from your katalon script, using java command runtime.getRuntime().exec("here is your exe with parameters), you just have to remember to use escape characters where needed.

PPPS.
fnr/fart commands are very helpful, you can change strings from jenkins in any files, not only in katalon scripts. I use it every day to change values in sql scripts which i run with sqlplus command.
and so on, and so on…

1 Like

Please have a look at this:

Hope this helps.

1 Like