Jenkins active choice parameter loses <scripts> in HTML

1.1k Views Asked by At

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

1

There are 1 best solutions below

1
Gerold Broser On

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).