Search code examples
jenkinsjenkins-pluginsjenkins-groovytestim.io

How to use variables in Jenkins Build command


I am trying to run Testim via Jenkins. I am using windows batch command for run it

testim --host localhost --port 4444 --mode selenium --token "xxxxxxxxx" --project "xxxxxxxxxx" --params-file ".\testdata.js" --name=%test1% --name=%test2%

Here i am expecting the names of tests that i need to run as the value of variable 'name'. For eg. if i have, total of 10 tests, and the user select 2 or some tests out that 10, those 2 or that much number of test names should be the value of the variables test1,test2,test3...etc respectively . So that the number of tests selected by a user while bulding, that much number of times the variable 'name' should come with respective test names in build command.I have tried it with Active choice parameter plugin of Jenkins, but it gives an array and i am not able to take single element of that array in Build command.As i am new to this, Can anyone help me?


Solution

  • You can achieve this easily using a pipeline job, by converting the input string to the format you need.

    Assuming you are using the Extended Choice parameter or similar, it will combine all selected values into a string, each value separated by your chosen separator. Assuming your parameter is called Names and the separator is ',' you can use the following:

    node {
        def nameFlags  = Names.split(',').collect { " --name=${it.trim()}" }
        bat "testim --host localhost --port 4444 --mode selenium --token \"xxx\" --project \"xxx\" --params-file \".\\testdata.js\" ${nameFlags.join(' ')}"
    }