Jenkins Groovy Parameters on Pipelines

109 views
Skip to first unread message

Ohad Cohen

unread,
Apr 25, 2017, 5:53:32 AM4/25/17
to Jenkins Users
Hi All,

i'm trying to override pipeline parameters using groovy code or declarative code.

i can't wrap this thing to work and i hope someone can help me figure out why.

while working with the declarative pipelines i have used the following code:

properties([
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '25')),
parameters([
string(defaultValue: 'someValue', description: '', name: 'someName'),
])
,pipelineTriggers([cron('H(0-0) 00 * * 1,2,5,6')])
])


the result is that every time i change some parameter default value it will take place only after running it twice (first run after change does not take the new value)

so i found this groovy way:

def npl = new ArrayList<StringParameterValue>()
for(param in propsObj.properties.parameters)
{
npl.add(new StringParameterValue(param.string.name, param.string.defaultValue,param.string.description))
}

def newPa = null
def oldPa = manager.build.getAction(ParametersAction.class)
if (oldPa != null) {
manager.build.removeAction(oldPa)
}

newPa = new ParametersAction(npl)


manager.build.actions.add(newPa)


-------- but this one doesn't work when using it from a global library.

does anyone know a better way to do this?
Reply all
Reply to author
Forward
0 new messages