扩展选择参数插件很棒,我在通过UI配置的作业中使用它https://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin
但是,我正努力让它在Jenkinsfile样式管道脚本中运行.由于Jenkins管道语法生成器创建了以下代码段,因此扩展选择参数插件似乎尚未与管道脚本完全兼容:
parameters([<object of type com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition>])
Run Code Online (Sandbox Code Playgroud)
如果我手动创建参数,我会得到与https://issues.jenkins-ci.org/browse/JENKINS-32188中提到的相同的行为
org.kohsuke.stapler.NoStaplerConstructorException: There's no @DataBoundConstructor on any constructor of class
Run Code Online (Sandbox Code Playgroud)
有没有人知道可以解决ExtendedChoiceParameterDefinition不使用问题的任何变通办法@DataBoundConstructor?
我正在尝试运行一个脚本来实例化扩展选择参数变量以在声明性 jenkinsfile 属性部分中使用它,但是我无法在没有步骤的情况下在 jenkinsfile 中运行脚本。我不想将其作为输入步骤或脚本管道来执行。
所以我运行它首先是一个节点步骤,然后是一个管道步骤,如下所示:
import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition
node('MyServer') {
try {
def multiSelect = new ExtendedChoiceParameterDefinition(...)
properties([ parameters([ multiSelect ]) ])
}
catch(error){
echo "$error"
}
}
pipeline {
stages {
....
}
}
Run Code Online (Sandbox Code Playgroud)
它神奇地起作用了!需要注意的是,仅当我之前仅使用管道块运行过构建时。
那么,有没有更好的方法来运行以前的脚本到管道?能够为属性或步骤之外的其他地方创建对象以嵌入脚本块?
jenkins-pipeline extended-choice-parameter jenkins-declarative-pipeline
我在声明性 Jenkins 管道中使用带有 JSON 参数类型的扩展选择参数。我发现它非常适合为参数提供自定义 UI,并且它会根据用户输入返回 json。
我有一个用例,其中向用户显示的选项取决于另一个参数的值。我可以通过主动选择参数来实现这样的功能,但随后我就陷入了单选按钮、复选框、html 输入等的困境。
我在这里找到了一个合适的选项,我可以使 json 内的属性依赖于另一个属性:
{
"title": "An object",
"type": "object",
"properties": {
"fieldOne": {
"title": "I should be changed to 'foo'",
"type": "string",
"enum": ["foo","bar"],
"default": "bar"
},
"depender1": {
"title": "I depend on fieldOne to be 'foo'",
"type": "string",
"enum": ["lorem","ipsum"],
"options": {
"dependencies": {
"fieldOne": "foo"
}
}
},
"depender2": {
"title": "I depend on fieldOne to be 'bar'",
"type": "string",
"enum": ["dolor", "sit"],
"options": …Run Code Online (Sandbox Code Playgroud) jenkins jenkins-plugins jenkins-pipeline extended-choice-parameter
有没有办法在 Jenkins 声明性管道参数中使用 Jenkins WORKSPACE 环境变量?
以下尝试失败。
pipeline {
parameters {
extendedChoice description: 'Template in project',
multiSelectDelimiter: ',', name: 'TEMPLATE',
propertyFile: env.WORKSPACE + '/templates.properties',
quoteValue: false, saveJSONParameterToFile: false, type: 'PT_MULTI_LEVEL_SINGLE_SELECT',
value: 'Project,Template', visibleItemCount: 6
...
}
stages {
...
}
Run Code Online (Sandbox Code Playgroud)
propertyFile: '${WORKSPACE}/templates.properties'也没有用。
environment-variables jenkins jenkins-plugins jenkins-pipeline extended-choice-parameter
jenkins ×3