Vladyslav Lishchyna
Vladyslav Lishchyna

Reputation: 91

Jenkins active choice parameter loses <scripts> in HTML

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

Upvotes: 2

Views: 1610

Answers (2)

secondmouse
secondmouse

Reputation: 1

If you delete the line "Settings.contains...", the function Test() can be found in HTML. Another way to resolve this is to change Test() to an inline function.
I'm looking for a better solution.

Upvotes: 0

Gerold Broser
Gerold Broser

Reputation: 14762

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

Upvotes: 2

Related Questions