【问题标题】:How to use Active Choices Reactive Reference Parameter in Jenkins pipeline(jenkinsfile)如何在 Jenkins 管道中使用 Active Choices Reactive Reference Parameter(jenkinsfile)
【发布时间】:2020-07-03 05:53:02
【问题描述】:

我想实现图3。如果不需要更新,给默认值。如果需要更新,则给用户输入区域。

我想在 Jenkins 管道代码中使用主动响应式参考,而不是 jenkins GUI。检查了example,但用户不能自己输入值,只能提供选择。正如我们所见,Jenkins GUI 图片 1 和 2 可以使用“格式化 HTML”来执行此操作,但我们如何在管道中使用它或将其转换为管道?

【问题讨论】:

  • 这个问题太难回答了?直到现在没有人可以帮助我

标签: jenkins-pipeline


【解决方案1】:

谢谢马克珠;

我遇到了同样的问题,这个解决方案真的很有帮助!

不过,您确实不需要使用 Jenkinsfile。您可以像这样将代码添加到反应参数中。

if(NeedUpgradePC.equals('yes')) {
  inputBox="<input name='value' type='text' value='Intel Core i5'>"
} else {
  inputBox="<input name='value' type='text' value='Intel Core i5' disabled>"
}

但更好的选择是停止使用文本并改用复选框。这是检查复选框值的方法。

  1. 使用标准布尔参数并将其命名为“NeedUpgradePC”
  2. 添加如下描述:“Intel Core i5”
  3. 在您的 Active Choices 响应式参考参数的 Groovy 脚本中:
if (NeedUpgradePC.equals('on')){
  inputBox="<input name='value' type='text' value='Intel Core i5'>"
} else {
  inputBox="<input name='value' type='text' value='Intel Core i5' disabled>"
}

【讨论】:

    【解决方案2】:

    ========我做到了======这里是代码。

     parameters([
                        choice(name:"NeedUpgradePC",choices:['yes','no'],description: "Do you need upgrade your PC"),
                        [$class: 'DynamicReferenceParameter',
                                choiceType: 'ET_FORMATTED_HTML',
                                omitValueField: true,
                                description: 'Please provide a Elastic alias label',
                                name: 'PC_RAM',
                                randomName: 'choice-parameter-5631314456178624',
                                referencedParameters: 'NeedUpgradePC',
                                script: [
                                        $class: 'GroovyScript',
                                        fallbackScript: [
                                                classpath: [],
                                                sandbox: true,
                                                script:
                                                        'return[\'nothing.....\']'
                                        ],
                                        script: [
                                                classpath: [],
                                                sandbox: true,
                                                script:
                                                        """
                                        if(NeedUpgradePC.equals('yes')) {
                                            inputBox="<input name='value' type='text' value='Kingston 8GB'>"
                                        } else {
                                            inputBox="<input name='value' type='text' value='Kingston 8GB' disabled>"
                                        }
                                    """
                                        ]
                                ]
                             ],
                                [$class: 'DynamicReferenceParameter',
                                        choiceType: 'ET_FORMATTED_HTML',
                                        omitValueField: true,
                                        description: 'Please provide a Elastic alias label',
                                        name: 'PC_CPU',
                                        randomName: 'choice-parameter-5631314456178624',
                                        referencedParameters: 'NeedUpgradePC',
                                        script: [
                                                $class: 'GroovyScript',
                                                fallbackScript: [
                                                        classpath: [],
                                                        sandbox: true,
                                                        script:
                                                                'return[\'nothing.....\']'
                                                ],
                                                script: [
                                                        classpath: [],
                                                        sandbox: true,
                                                        script:
                                                                """
                                        if(NeedUpgradePC.equals('yes')) {
                                            inputBox="<input name='value' type='text' value='Intel Core i5'>"
                                        } else {
                                            inputBox="<input name='value' type='text' value='Intel Core i5' disabled>"
                                        }
                                    """
                                                ]
                                        ]
                                ]
    
                ])
    

    【讨论】:

      猜你喜欢
      • 2021-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 2016-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多