如何在Jenkins Declarative Pipeline中从DynamicReferenceParameter呈现的输入标记中获取值

wgx48brx  于 2023-10-17  发布在  Jenkins
关注(0)|答案(1)|浏览(144)

这是我的代码,choice2依赖于choice。我如何在管道中获得输入标记的值(值来自用户)。

properties([
    parameters([
        
        [
            $class: 'ChoiceParameter', 
            choiceType: 'PT_RADIO', 
            description: 'Select a choice', 
            filterLength: 1, 
            filterable: false, 
            name: 'choice1', 
            randomName: 'choice-parameter-7601235200970', 
            script: [
                $class: 'GroovyScript', 
                fallbackScript: [
                    classpath: [], 
                    sandbox: false, 
                    script: 'return ["ERROR"]'
                ], 
                script: [
                    classpath: [], 
                    sandbox: true, 
                    script: 'return[\'aaa\',\'bbb\']'
                ]
            ]
        ], 
        
        [
            $class: 'DynamicReferenceParameter', 
            choiceType: 'ET_FORMATTED_HTML', 
            name: 'choice2', 
            referencedParameters: 'choice1', 
            description: 'Active Choices Reactive parameter', 
            omitValueField: true,
            randomName: 'choice-parameter-7601237141171', 
            script: [
                $class: 'GroovyScript', 
                fallbackScript: [
                    classpath: [], 
                    sandbox: false, 
                    script: 'return ["error"]'
                ], 
                script: [
                    classpath: [], 
                    sandbox: true, 
                    script: 'if(choice1.equals("aaa")){return "<input name=\'Aws\' value=\'\' class=\'setting-input\' type=\'text\'>"} else {return "Not Required"}'
                ]
            ]
        ]
        
        
    ])
])

pipeline {
    agent any

    stages {
        stage('Print the Values') {
            steps {
                script{
                    echo "${params.choice2}"
                }
            }
        }
    }
}

我想要用户输入的值。它的值为null。谁能帮帮我。

jxct1oxe

jxct1oxe1#

如果我理解正确的话,参数应该根据用户提供的内容显示。
下面是我的帖子,也是同样的问题:Jenkins dynamic passing of a variable to a parameter
老实说,我花了很多时间试图解决这个问题,但我失败了。

相关问题