如何在groovy脚本中启用/禁用文本框 [英] how to enable/disable a textbox in groovy script

查看:85
本文介绍了如何在groovy脚本中启用/禁用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Jenkins管道中有几个参数.我的第一个参数是选择,第二个参数是输入框,其中包含字符串.

I have couple of parameters in my Jenkins pipeline. Where my first parameter is choice and my second parameter is Input Box contains string.

这里的挑战是,当我在第一个参数中选择第一个值时,应启用第二个参数(输入框),否则请启用.我目前在第二个参数中使用扩展选择参数,在这里我选择文本框".作为参数类型.有人可以帮我解决在选择其他参数值时如何启用和禁用参数输入.

My challenge here is, when I select first value in the first parameter, 2nd parameter (input box) should be enabled if not it should not. I am currently using Extended Choice Parameter for 2nd parameter where I choose "Text Box" as parameter type. Could someone help me out how to enable and disable the parameter input on selecting values of different parameter.

例如: P1-选择参数值:启用,禁用P2-扩展选择参数:(文本框)

推荐答案

在这种情况下,P2必须为DynamicReferenceParameter,具体取决于P1.

P2 has to be DynamicReferenceParameter in this case, depending on P1.

[$class: 'DynamicReferenceParameter', 
choiceType: 'ET_FORMATTED_HTML', 
description: '',
name: 'P2', 
omitValueField: true,
randomName: 'choice-parameter-123456', 
referencedParameters: 'P1',
script: [
    $class: 'GroovyScript', 
    fallbackScript: [
        classpath: [],
        sandbox: true,
        script: 
            'return [\'Error message\']'
    ], 
    script: [
        classpath: [], 
        sandbox: true,
        script: 
            """ 
                html=""
                if (P1.equals("firstValue")){
                    
                        html="<input name='value' value='' class='setting-input' type='text'>"
                }
                else {
                    html="Not applicable"
                }
                return html
            """
    ]
] ]

这篇关于如何在groovy脚本中启用/禁用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆