Class ScriptHelper

java.lang.Object
org.jenkinsci.plugins.scriptler.util.ScriptHelper

public final class ScriptHelper extends Object
Author:
Dominik Bartholdi (imod)
  • Method Details

    • readScriptFromFile

      @NonNull public static String readScriptFromFile(@NonNull Path path) throws IOException
      Throws:
      IOException
    • writeScriptToFile

      public static void writeScriptToFile(@NonNull Path path, @NonNull String script) throws IOException
      Throws:
      IOException
    • getScript

      @CheckForNull public static Script getScript(@CheckForNull String id, boolean withSrc)
      Loads the script information.
      Parameters:
      id - the id of the script
      withSrc - 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(@NonNull String scriptSourceCode)
    • isApproved

      public static boolean isApproved(@CheckForNull 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
    • isApproved

      public static boolean isApproved(@CheckForNull String scriptSourceCode, boolean putInApprovalQueueIfNotApprovedYet)
      Parameters:
      scriptSourceCode - Source code that must be approved
      putInApprovalQueueIfNotApprovedYet - 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.
      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

      public static ScriptInfo extractScriptInfo(String fullScriptBody)
      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: