Class ScriptHelper
java.lang.Object
org.jenkinsci.plugins.scriptler.util.ScriptHelper
- Author:
- Dominik Bartholdi (imod)
-
Method Summary
Modifier and TypeMethodDescriptionstatic ScriptInfo
extractScriptInfo
(String fullScriptBody) Returns the meta info of a script body, which must follow the conventionstatic Script
Loads the script information.static boolean
isApproved
(String scriptSourceCode) static boolean
isApproved
(String scriptSourceCode, boolean putInApprovalQueueIfNotApprovedYet) static void
putScriptInApprovalQueueIfRequired
(String scriptSourceCode) static String
readScriptFromFile
(Path path) static String
runScript
(String[] computers, String scriptText, Collection<Parameter> parameters) Deprecated.static String
runScript
(String node, String scriptTxt, Collection<Parameter> parameters) Runs the execution on a given agent.static String
static void
writeScriptToFile
(Path path, String script)
-
Method Details
-
readScriptFromFile
- Throws:
IOException
-
writeScriptToFile
- Throws:
IOException
-
getScript
Loads the script information.- Parameters:
id
- the id of the scriptwithSrc
- should the script sources be loaded too?- Returns:
- the script -
null
if the id is not set or the script with the given id can not be resolved
-
putScriptInApprovalQueueIfRequired
-
isApproved
- Parameters:
scriptSourceCode
- Source code that must be approved- Returns:
- true if the script was approved or created by a user with RUN_SCRIPT permission
-
isApproved
public static boolean isApproved(@CheckForNull String scriptSourceCode, boolean putInApprovalQueueIfNotApprovedYet) - Parameters:
scriptSourceCode
- Source code that must be approvedputInApprovalQueueIfNotApprovedYet
- true means we try to know if the user has permission to approve the script automatically in case it was not approved yet- Returns:
- true if the script is approved
-
runScript
@Deprecated(since="381") public static String runScript(String[] computers, String scriptText, @NonNull Collection<Parameter> parameters) throws IOException, jakarta.servlet.ServletException Deprecated.UserunScript(List, String, Collection)
instead.- Throws:
IOException
jakarta.servlet.ServletException
-
runScript
public static String runScript(List<String> computers, String scriptText, @NonNull Collection<Parameter> parameters) throws IOException, jakarta.servlet.ServletException - Throws:
IOException
jakarta.servlet.ServletException
-
runScript
public static String runScript(String node, String scriptTxt, @NonNull Collection<Parameter> parameters) throws IOException, jakarta.servlet.ServletException Runs the execution on a given agent.- Parameters:
node
- where to run the script.scriptTxt
- the script (groovy) to be executed.- Returns:
- the output
- Throws:
IOException
jakarta.servlet.ServletException
-
extractScriptInfo
Returns the meta info of a script body, which must follow the convention- Parameters:
fullScriptBody
- the script to extract the meta info from- Returns:
null
if no meta info found- See Also:
-
runScript(List, String, Collection)
instead.