1

I use Scriptler plagin and active choice parameters that return html. Now I need insert section in that html. I try do it like this

if (!Settings.contains("ExtraDeployTargets"))
{
    return "";
}

html =
  """
<script>
    function Test(selectObject)
    {
        console.log("Hi");
    }
</script>

<label style="font-size: 14px; font-weight: bold; display: inline;">
    Choose number of additional instances:
</label>
<select name="value" style="height: 30px; font-size: 14px; display: inline-block;", onchange="Test(this)">
    <option value="AdditionalInstancesCount=0">1</option>
    <option value="AdditionalInstancesCount=1">1</option>
    <option value="AdditionalInstancesCount=2">2</option>
    <option value="AdditionalInstancesCount=3">3</option>
    <option value="AdditionalInstancesCount=4">4</option>
    <option value="AdditionalInstancesCount=5">5</option>
</select>
  """

return html;

enter image description here

But function not work in HTML. Also in page HTML code absent onchange property and section

enter image description here

The question is - "How insert script in HTML in JenkinsFile?"

Duskone39
  • 61
  • 7
  • Just out of curiosity: Why do you use `"""` instead of `'''` if there's nothing to interpolate inside the string? Why don't you `return ''' ... '''` directly? – Gerold Broser Oct 27 '21 at 21:27

1 Answers1

1

See the Active Choices Reactive Reference ParameterGroovy Script inline help:

If this script is used for any of the HTML choice types of an Active Choices Reactive Reference Parameter, the resulting HTML output will be sanitized to remove everything but basic formatting, like script tags, unless the script runs outside the sandbox. This mode requires approval from a Jenkins administrator to prevent cross-site scripting (HTML) and arbitrary code execution (Groovy).

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107