How to use Active Choices Reactive Reference Parameter in Jenkins pipeline(jenkinsfile)

前端 未结 2 2140
感动是毒
感动是毒 2021-01-24 04:22

I want achieve Picture 3. If no need update, give default value. If need update, then give user input area.

I\'d like use active reactive Reference in Jenkins pipeline

相关标签:
2条回答
  • 2021-01-24 04:57

    Thanks Markzhu;

    I ran into the same problem and this solution really helped!

    You really don't need to use a Jenkinsfile though. You can just add the code to the reactive parameter like this.

    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>"
    }
    

    But the better option is to stop using text and use a checkbox instead. Here is how you check the value of a checkbox.

    1. Use a standard Boolean Parameter and name it 'NeedUpgradePC'
    2. Add a description like: "Intel Core i5"
    3. In the Groovy Script for your Active Choices Reactive Reference Parameter:
    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>"
    }
    
    0 讨论(0)
  • 2021-01-24 05:08

    ========I made it====== here is the code.

     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>"
                                        }
                                    """
                                                ]
                                        ]
                                ]
    
                ])
    
    0 讨论(0)
提交回复
热议问题