Katsuya Tomioka
Katsuya Tomioka

Reputation: 13

jenkins pipeline additional parameters

I have a step in a shared library to set build properties with some common parameters. I'm trying to pass additional parameters to the step such that:

def call(buildParams = []) {
  def commonParams = [
        booleanParam(name: 'release', defaultValue: false, description: 'Release the project'),
  ]
  properties([
        parameters(commonParams + buildParams)
  ])
}

I'm calling this like:

standardProperties(buildParams = [booleanParam(name: 'test', defaultValue: false, description: 'test'))

However I get an NPE:

java.lang.NullPointerException
at org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep$Execution.run(JobPropertyStep.java:127)
at org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep$Execution.run(JobPropertyStep.java:92)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution.start(AbstractSynchronousStepExecution.java:42)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:229)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:153)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

Upvotes: 1

Views: 524

Answers (1)

Sam
Sam

Reputation: 2882

So the invocation of your standardProperties method doesn't need to specify buildParams =, this is part of the interface. Try:

standardProperties([booleanParam(name: 'test', defaultValue: false, description: 'test')])

For easy reading I recommend

List params = [
    booleanParam(name: 'test', defaultValue: false, description: 'test')
]
standardProperties(params)

Upvotes: 1

Related Questions