Class ScriptHelper


  • public class ScriptHelper
    extends Object
    Author:
    Dominik Bartholdi (imod)
    • Constructor Detail

      • ScriptHelper

        public ScriptHelper()
    • Method Detail

      • getScript

        @CheckForNull
        public static Script getScript​(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​(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 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
        Since:
        TODO
      • 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:
        ...