Class ScriptHelper
- java.lang.Object
-
- org.jenkinsci.plugins.scriptler.util.ScriptHelper
-
public class ScriptHelper extends Object
- Author:
- Dominik Bartholdi (imod)
-
-
Constructor Summary
Constructors Constructor Description ScriptHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ScriptInfo
extractScriptInfo(String fullScriptBody)
Returns the meta info of a script body, the meta info has to follow the convention at https://github.com/jenkinsci/jenkins-scripts/tree/master/scriptlerstatic Script
getScript(String id, boolean withSrc)
Loads the script information.static boolean
isApproved(String scriptSourceCode)
static boolean
isApproved(String scriptSourceCode, boolean putInApprovalQueueIfNotApprovedYet)
static void
putScriptInApprovalQueueIfRequired(String scriptSourceCode)
static String
readScriptFromFile(File file)
static String
runScript(String[] slaves, String scriptTxt, Collection<Parameter> parameters)
static String
runScript(String node, String scriptTxt, Collection<Parameter> parameters)
Runs the execution on a given slave.static void
writeScriptToFile(File file, String script)
-
-
-
Method Detail
-
readScriptFromFile
@NonNull public static String readScriptFromFile(@NonNull File file) throws IOException
- Throws:
IOException
-
writeScriptToFile
public static void writeScriptToFile(@NonNull File file, @NonNull String script) throws IOException
- Throws:
IOException
-
getScript
@CheckForNull public static Script getScript(String id, boolean withSrc)
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
public static void putScriptInApprovalQueueIfRequired(String scriptSourceCode)
- Since:
- TODO
-
isApproved
public static boolean isApproved(String scriptSourceCode)
- Parameters:
scriptSourceCode
- Source code that must be approved- Returns:
- true if the script was approved or created by a user with RUN_SCRIPT permission
- Since:
- TODO
-
isApproved
public static boolean isApproved(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
- Since:
- TODO
-
runScript
public static String runScript(String[] slaves, String scriptTxt, @NonNull Collection<Parameter> parameters) throws IOException, javax.servlet.ServletException
- Throws:
IOException
javax.servlet.ServletException
-
runScript
public static String runScript(String node, String scriptTxt, @NonNull Collection<Parameter> parameters) throws IOException, javax.servlet.ServletException
Runs the execution on a given slave.- Parameters:
node
- where to run the script.scriptTxt
- the script (groovy) to be executed.- Returns:
- the output
- Throws:
IOException
javax.servlet.ServletException
-
extractScriptInfo
public static ScriptInfo extractScriptInfo(String fullScriptBody)
Returns the meta info of a script body, the meta info has to follow the convention at https://github.com/jenkinsci/jenkins-scripts/tree/master/scriptler- Parameters:
fullScriptBody
- the script to extract the meta info from- Returns:
null
if no meta info found- See Also:
- ...
-
-