How to add parameters to existing parameters list?

19 views
Skip to first unread message

Gajanan Mahajan

unread,
Aug 4, 2020, 2:03:39 AM8/4/20
to Jenkins Users
I get all parameters of a build using -

    def myparams = currentBuild.rawBuild.getAction(ParametersAction).getParameters()

`myparams` is object of `java.util.Collections$UnmodifiableRandomAccessList` hence if try  to add another parameter to it like  -

    myparams.add([$class: 'StringParameterValue', name: 'Test', value: "TestValue"])

then it fails with error - 

    java.lang.UnsupportedOperationException

Please guide how to add parameter to existing parameters.

Stuart Rowe

unread,
Aug 5, 2020, 1:07:27 AM8/5/20
to Jenkins Users
You can configure the parameters for the current job (in a Scripted Pipeline) with:

def parameterList = [stringParam(name: 'Test', value: 'TestValue')]
properties
(parameters(parameterList)

This will replace all parameters of your job with the contents of parameterList.
Reply all
Reply to author
Forward
0 new messages