Reputation: 91
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;
But function not work in HTML. Also in page HTML code absent onchange property and section
The question is - "How insert script in HTML in JenkinsFile?"
Upvotes: 2
Views: 1610
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
Reputation: 14762
See the Active Choices Reactive Reference Parameter → Groovy 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