管道中定义的 DynamicReferenceParameter
DynamicReferenceParameter defined in Pipeline
我将 DynamicReferenceParameter 用于 Jenkins 中的一些高级参数输入。
这是我使用 UI 输入的一个小示例:
这很好用,我的复选框和输入字段确实显示了!
但是当我尝试在我的 Jenkinsfile 中定义我的参数时,出现错误。我的 Jenkinsfile 看起来像这样:
properties([parameters([
[
$class: 'DynamicReferenceParameter',
name: 'SFM',
script: [
$class: 'GroovyScript',
fallbackScript: '',
script: """
def services = ['service1',
'service2',
'service3']
def html =
'''
<!DOCTYPE html>
<html>
<body>
<table id="serviceTable">
'''
for (service in services){
html += "<tr>"
html += "<td><input type=\"checkbox\" id=\"checkbox_$service\">$service</td>"
html += "<td><div id=\"version_$service\" >version: <input type=\"text\"></div></td>"
html += "</tr>"
}
html += '''
</table>
</body>
</html>
'''
return html
"""
]
]
])])
你看,我只是从 UI 输入中复制并粘贴脚本,并用 """
包围它。
这导致错误编号。 1:
Groovy.lang.MissingPropertyException: No such property: service for class: WorkflowScript
所以解析我的变量时出错。
所以我只是尝试删除所有变量并设置静态值(将 $service
替换为 service1
)。这导致错误编号。 2:
java.lang.ClassCastException: org.biouno.unochoice.model.GroovyScript.script expects class org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript but received class java.lang.String
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:416)
at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:340)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:281)
Caused: java.lang.IllegalArgumentException: Could not instantiate {fallbackScript=, script=[...]
我做错了什么?
script
和 fallbackScript
不是真正的字符串。他们正在使用安全脚本插件 类(已经有一段时间了)。
下面是一些可能有用的代码片段。
properties([parameters([
[
$class: 'DynamicReferenceParameter',
name: 'TEST',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [], sandbox: true, script: ''
],
script: [
classpath: [], sandbox: true, script:
"""
def html =
'''
<!DOCTYPE html>
<html>
<body>
<table id="serviceTable">
<tr>
<td><input type="checkbox" id="checkbox">service1</td>
<td><div id="version" >version: <input type="text"></div></td>
</tr>
</table>
</body>
</html>
'''
return html
"""
]
]
]
])])
ps:对它持保留态度,因为我通常只使用 FreeStyle 作业。我认为有些人尝试将插件与管道一起使用,但据我所知,它仍在进行中(例如参见 [=13=])
希望有所帮助ps,
布鲁诺
我将 DynamicReferenceParameter 用于 Jenkins 中的一些高级参数输入。
这是我使用 UI 输入的一个小示例:
这很好用,我的复选框和输入字段确实显示了!
但是当我尝试在我的 Jenkinsfile 中定义我的参数时,出现错误。我的 Jenkinsfile 看起来像这样:
properties([parameters([
[
$class: 'DynamicReferenceParameter',
name: 'SFM',
script: [
$class: 'GroovyScript',
fallbackScript: '',
script: """
def services = ['service1',
'service2',
'service3']
def html =
'''
<!DOCTYPE html>
<html>
<body>
<table id="serviceTable">
'''
for (service in services){
html += "<tr>"
html += "<td><input type=\"checkbox\" id=\"checkbox_$service\">$service</td>"
html += "<td><div id=\"version_$service\" >version: <input type=\"text\"></div></td>"
html += "</tr>"
}
html += '''
</table>
</body>
</html>
'''
return html
"""
]
]
])])
你看,我只是从 UI 输入中复制并粘贴脚本,并用 """
包围它。
这导致错误编号。 1:
Groovy.lang.MissingPropertyException: No such property: service for class: WorkflowScript
所以解析我的变量时出错。
所以我只是尝试删除所有变量并设置静态值(将 $service
替换为 service1
)。这导致错误编号。 2:
java.lang.ClassCastException: org.biouno.unochoice.model.GroovyScript.script expects class org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript but received class java.lang.String
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:416)
at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:340)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:281)
Caused: java.lang.IllegalArgumentException: Could not instantiate {fallbackScript=, script=[...]
我做错了什么?
script
和 fallbackScript
不是真正的字符串。他们正在使用安全脚本插件 类(已经有一段时间了)。
下面是一些可能有用的代码片段。
properties([parameters([
[
$class: 'DynamicReferenceParameter',
name: 'TEST',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [], sandbox: true, script: ''
],
script: [
classpath: [], sandbox: true, script:
"""
def html =
'''
<!DOCTYPE html>
<html>
<body>
<table id="serviceTable">
<tr>
<td><input type="checkbox" id="checkbox">service1</td>
<td><div id="version" >version: <input type="text"></div></td>
</tr>
</table>
</body>
</html>
'''
return html
"""
]
]
]
])])
ps:对它持保留态度,因为我通常只使用 FreeStyle 作业。我认为有些人尝试将插件与管道一起使用,但据我所知,它仍在进行中(例如参见 [=13=])
希望有所帮助ps, 布鲁诺