我正在尝试通过管道库在Jenkins“输入步骤”中实现灵活的UI,目前我使用的是扩展选择参数插件(https://wiki.jenkins.io/display/JENKINS/Extended+Choice+Parameter+plugin),该插件建立在Json编辑器库({{3 }}),并用于提供各种HTML输入元素(从JSON模式创建)并生成JSON输出。
“输入步骤”是否可以接受一些html模板代码来填充数据,这些数据是在构建期间收集的,并使用一些自定义HTML元素和js绑定将其打印在“输入步骤”页面上,而不是“扩展选择参数”所提供的输入形式“?
现在,我正在通过groovy共享库脚本生成动态下拉列表,但是无法使其在“输入步骤页面”非输入元素上打印。
答案 0 :(得分:1)
一切都很简单,ExtendedChoiceParameterDefinition的参数为“ String javascript”,它可以接受任何js字符串,不仅可以为Json编辑器返回JSON字符串,还可以修改输入页面本身。
管道示例:
stage('UserInput'){
steps {
script {
//...groovy script is omitted, it need only return json in valid form
def jsString = '''
var bodyElement = document.createElement('div');
bodyElement.innerHTML = '<h1 id="title">Some Title</h1><span style="display:inline-block; width=100px;">Some arbitrary text</span>';
document.getElementsByTagName('body')[0].appendChild(bodyElement);'''
def jsonParams = new ExtendedChoiceParameterDefinition(
'Cookbooks', //String name,
'PT_JSON', //String type,
null, //String value,
null, //String projectName,
null, //String propertyFile,
jsonGroovyScript, //String groovyScript (that returns JSON for generating Json-Input forms),
null, //String groovyScriptFile,
"jsonText=$jsonText", //String bindings,
'', //String groovyClasspath,
null, //String propertyKey,
null, //String defaultValue,
null, //String defaultPropertyFile,
null, //String defaultGroovyScript,
null, //String defaultGroovyScriptFile,
null, //String defaultBindings,
null, //String defaultGroovyClasspath,
null, //String defaultPropertyKey,
null, //String descriptionPropertyValue,
null, //String descriptionPropertyFile,
null, //String descriptionGroovyScript,
null, //String descriptionGroovyScriptFile,
null, //String descriptionBindings,
null, //String descriptionGroovyClasspath,
null, //String descriptionPropertyKey,
null, //String javascriptFile,
jsString, //String javascript (js code that modify input page itself),
false, //boolean saveJSONParameterToFile,
false, //boolean quoteValue,
10, //int visibleItemCount,
'', //String description,
',' //String multiSelectDelimiter
))
parameterList << jsonParams
def form = input(
id: 'form', message: 'input parameters', parameters: parameterList
) // generating input page step and store it in "form" var
env.FORM = form
}
}
}