詹金斯管道附加参数

时间:2018-07-04 02:17:33

标签: jenkins jenkins-pipeline

我在共享库中迈出了一步,以使用一些常用参数设置构建属性。我正在尝试将其他参数传递给该步骤,例如:

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

我这样称呼:

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

但是我得到了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)

1 个答案:

答案 0 :(得分:0)

因此,调用standardProperties方法无需指定buildParams =,这是接口的一部分。试试:

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

为便于阅读,我建议

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