Class ScriptHelper
java.lang.Object
org.jenkinsci.plugins.scriptler.util.ScriptHelper
- Author:
- Dominik Bartholdi (imod)
-
Method Summary
Modifier and TypeMethodDescriptionstatic ScriptInfoextractScriptInfo(String fullScriptBody) Returns the meta info of a script body, which must follow the conventionstatic ScriptLoads the script information.static booleanisApproved(String scriptSourceCode) static booleanisApproved(String scriptSourceCode, boolean putInApprovalQueueIfNotApprovedYet) static voidputScriptInApprovalQueueIfRequired(String scriptSourceCode) static StringreadScriptFromFile(Path path) static StringrunScript(String[] computers, String scriptText, Collection<Parameter> parameters) Deprecated.static StringrunScript(String node, String scriptTxt, Collection<Parameter> parameters) Runs the execution on a given agent.static Stringstatic voidwriteScriptToFile(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 -
nullif 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:
IOExceptionjakarta.servlet.ServletException
-
runScript
public static String runScript(List<String> computers, String scriptText, @NonNull Collection<Parameter> parameters) throws IOException, jakarta.servlet.ServletException - Throws:
IOExceptionjakarta.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:
IOExceptionjakarta.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:
nullif no meta info found- See Also:
-
runScript(List, String, Collection)instead.