How to get value from input in DynamicReferenceParameter

Hi,
I need get value from input (for example “threads”):

[$class: 'DynamicReferenceParameter',
            name: 'strategyParams',
            referencedParameters: 'strategySelect',
            choiceType: 'ET_FORMATTED_HTML',
            description: 'Ustaw parametry strategii',
            script: [
                $class: 'GroovyScript',
                fallbackScript: [
                    classpath: [],
                    sandbox: true,
                    script: 'return ["Parametry strategii są dostępne tylko dla Fatality po wybraniu strategii. Pozostałe testy są już sparametryzowane."]'
                ],
                script: [
                    classpath: [],
                    sandbox: true,
                    script: """
                        if (strategySelect == 'Simple') {
                            return '''
                                <p><b>Liczba wątków</b><br><input type="text" class=" " id="threads" name="value" value="" placeholder="Thread"></p>
                                <p><b>Maksymalne opóźnienie pomiędzy testami (w milisekundach)</b><br><input type="text" class="" id="testDelay" name="value" value="" placeholder="Test Delay"></p>
                                <p><b>Odchylenie od maksymalnego opóźnienia (wartości od 0.1 do 0.9 - uwaga na kropkę zamiast przecinka)</b><br><input type="text" class="" id="randomFactor" name="value" value="0.5" placeholder="Random"></p>
                                <p><b>Wartość limitu</b><br><input type="text" class="" id="testLimit" name="value" value="" placeholder="Test Limit"></p>
                            '''

and put it into testrunner

sh "/opt/SoapUI-5.7.0/bin/testrunner.sh -P envSelect=${envSelect} -P testCaseSelect=${testCaseSelect} -P loadTestSelect=${loadTestSelect} -P strategySelect=${strategySelect} -P threads=${params.threads} -P testDelay=${params.testDelay} -P randomFactor=${params.randomFactor} -P limitType=${limitType} -P testLimit=${params.testLimit} loadTests.xml -s Load -c Config -r"

I tried -P threads=${strategyParams["threads"]} and -P threads=${threads} and after job run I see in jenkins console empty value -P threads= , and -P threads=${params.threads} but then I got null.

Can anybody help me with this? :slight_smile:

Hi, @marecki !

From my experience, parameters are designed to return just strings as values, not a Java constructions (like Maps, Lists, etc).
There is two ways how to solve your case: Hack and Jenkins way.
Jenkins way is to split all your inputs to separate parameters. Also, please note - if you use custom inputs in choice type ET_FORMATTED_HTML, you should set omitValueField: true.

Hack is that you still can use one ET_FORMATTED_HTML parameter for all your inputs. And combine all this inputs using Javascript to one string, splitted by ,. In this case you can use your parameters in pipeline like this:

List strategyParams = params.strategyParams.tokenize(',')
sh ".... -P testDelay=${strategyParams[0]} -P randomFactor=${strategyParams[1]} -P limitType=${strategyParams[2]} -P testLimit=${strategyParams[3]} ...."

Really bad way because you would need to maintain Javascript, parameter html and pipeline code to make sure the order is correct.

1 Like

Thanks a lot :slight_smile:

You really helped me!

1 Like