小编izz*_*kil的帖子

如何使用Jenkins Pipeline属性步骤?

我正在研究Jenkins Pipeline:Multibranch的功能.据说最近推出的properties步骤在那里可能有用,但我无法理解它是如何工作的以及它的目的是什么.

它的提示信息似乎不是很清楚:

更新运行此步骤的作业的属性.主要用于多分支工作流,因此Jenkinsfile本身可以编码静态作业配置.

所以我用这个脚本创建了一个新的Pipeline(直接粘贴到Jenkins而不是SCM中):

properties [[$class: 'ParametersDefinitionProperty',
   parameterDefinitions: [[$class: 'StringParameterDefinition',
       defaultValue: '', description: '', name: 'PARAM1']]
]]
Run Code Online (Sandbox Code Playgroud)

我运行它并没有发生任何事情,工作没有收到一个新的参数,即使它确实我没有得到为什么我可能需要这个.有人可以解释一下吗?

UPDATE1:我尝试将带有属性步骤的虚拟管道放入我的git仓库,然后配置了一个多分支作业.

println 1
properties [[$class: 'ParametersDefinitionProperty', parameterDefinitions: [[$class: 'StringParameterDefinition', defaultValue: 'str1', description: '', name: 'PARAM1']]], [$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false]]
println 2
Run Code Online (Sandbox Code Playgroud)

它找到了我的分支,创建了一个工作,但构建失败了:

groovy.lang.MissingPropertyException: No such property: properties for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:62)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:185)
at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:241)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:238)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:23)
at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:17)
at WorkflowScript.run(WorkflowScript:2)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:62)
at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) …
Run Code Online (Sandbox Code Playgroud)

jenkins jenkins-workflow jenkins-pipeline

47
推荐指数
2
解决办法
5万
查看次数