Search code examples
htmljenkinsgroovyjenkins-pipeline

jenkins, declartive pipeline - adding multi-line default to input textarea


I have the following DynamicReferenceParamter define which is used to change the input type from text to textarea depending on a selection the user makes. It works fine for when I use test1 as is shown in the code below - the textarea is displayed with value 1234, when I change that to test2 however, which has a multi-line string, the textarea is not rendered. I do not see any errors so hard to debug this...

def test1 = '1234'
def test2 = '''
            1234
            5678
            91011
            '''
                
properties([
    parameters([
        [$class: 'DynamicReferenceParameter', 
            choiceType: 'ET_FORMATTED_HTML', 
            description: 'enter job params',
            name: 'jobArgs', 
            referencedParameters: 'lstSelection, test1, test2',
            script: 
                [$class: 'GroovyScript', 
                script: [
                        sandbox: true, 
                        script: """
                            def html
                            if (lstSelection == 'build'){
                               html = '<textarea name="value" rows="5" class="setting-input">' + '${test1}' + '</textarea>'
                            }else{
                                html = '<input type="text" name="value" placeholder="{args}" >'
                            }
                            return html
                        """
                    ] 
            ],
        omitValueField: true
        ],
    ])
])

Solution

  • i was able to solve this using the following:

    html = '<textarea name="value" rows="5" class="setting-input">' + `'''${test2}'''` + '</textarea>'
    

    If no one has a better answer..will mark it answered in a few days