Class ScriptlerManagement

java.lang.Object
hudson.model.ManagementLink
org.jenkinsci.plugins.scriptler.ScriptlerManagement
All Implemented Interfaces:
ExtensionPoint, Action, ModelObject, RootAction

@Extension public class ScriptlerManagement extends ManagementLink implements RootAction
Creates the link on the "manage Jenkins" page and handles all the web requests.
Author:
Dominik Bartholdi (imod)
  • Constructor Details

    • ScriptlerManagement

      public ScriptlerManagement()
  • Method Details

    • getScriptlerRunScripts

      public Permission getScriptlerRunScripts()
    • getScriptlerConfigure

      public Permission getScriptlerConfigure()
    • hasAtLeastOneScriptlerPermission

      public boolean hasAtLeastOneScriptlerPermission()
    • checkAtLeastOneScriptlerPermission

      public void checkAtLeastOneScriptlerPermission()
    • getIconFileName

      public String getIconFileName()
      Specified by:
      getIconFileName in interface Action
      Specified by:
      getIconFileName in class ManagementLink
    • getCategory

      @NonNull public ManagementLink.Category getCategory()
      Overrides:
      getCategory in class ManagementLink
    • getUrlName

      public String getUrlName()
      Specified by:
      getUrlName in interface Action
      Specified by:
      getUrlName in class ManagementLink
    • disableRemoteCatalog

      public boolean disableRemoteCatalog()
    • getDisplayName

      public String getDisplayName()
      Specified by:
      getDisplayName in interface Action
      Specified by:
      getDisplayName in interface ModelObject
    • getDescription

      public String getDescription()
      Overrides:
      getDescription in class ManagementLink
    • getScriptler

      public ScriptlerManagement getScriptler()
    • getConfiguration

      public ScriptlerConfiguration getConfiguration()
    • getMarkupFormatter

      public MarkupFormatter getMarkupFormatter()
    • doScriptlerSettings

      public org.kohsuke.stapler.HttpResponse doScriptlerSettings(org.kohsuke.stapler.StaplerRequest2 res, org.kohsuke.stapler.StaplerResponse2 rsp, @QueryParameter("disableRemoteCatalog") boolean disableRemoteCatalog) throws IOException
      save the scriptler 'global' settings (on settings screen, not global Jenkins config)
      Throws:
      IOException
    • doDownloadScript

      public org.kohsuke.stapler.HttpResponse doDownloadScript(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, @QueryParameter("id") String id, @QueryParameter("catalog") String catalogName) throws IOException
      Downloads a script from a catalog and imports it to the local system.
      Parameters:
      req - request
      rsp - response
      id - the id of the file to be downloaded
      catalogName - the catalog to download the file from
      Returns:
      same forward as from doScriptAdd
      Throws:
      IOException
    • doScriptAdd

      public org.kohsuke.stapler.HttpResponse doScriptAdd(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, @QueryParameter("id") String id, @QueryParameter("name") String name, @QueryParameter("comment") String comment, @QueryParameter("script") String script, @QueryParameter("nonAdministerUsing") boolean nonAdministerUsing, @QueryParameter("onlyController") boolean onlyController, String originCatalogName, String originId) throws IOException, jakarta.servlet.ServletException
      Saves a script snippet as file to the system.
      Parameters:
      req - response
      rsp - request
      id - the script id (fileName)
      name - the name of the script
      comment - a comment
      script - script code
      nonAdministerUsing - allow usage in Scriptler build step
      onlyController - this script is only allowed to run on the controller
      originCatalogName - (optional) the name of the catalog the script is loaded/added from
      originId - (optional) the original id the script had at the catalog
      Returns:
      forward to 'index'
      Throws:
      IOException
      jakarta.servlet.ServletException
    • getGitRepo

      @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public GitScriptlerRepository getGitRepo()
    • doHardResetGit

      public org.kohsuke.stapler.HttpResponse doHardResetGit() throws IOException
      Triggers a hard reset on the git repo
      Returns:
      redirects to the repo entry page at /scriptler.git
      Throws:
      IOException
    • doRemoveScript

      public org.kohsuke.stapler.HttpResponse doRemoveScript(org.kohsuke.stapler.StaplerRequest2 res, org.kohsuke.stapler.StaplerResponse2 rsp, @QueryParameter("id") String id) throws IOException
      Removes a script from the config and filesystem.
      Parameters:
      res - response
      rsp - request
      id - the id of the file to be removed
      Returns:
      forward to 'index'
      Throws:
      IOException
    • doUploadScript

      public org.kohsuke.stapler.HttpResponse doUploadScript(org.kohsuke.stapler.StaplerRequest2 req) throws IOException, jakarta.servlet.ServletException
      Uploads a script and stores it with the given filename to the configuration. It will be stored on the filessytem.
      Parameters:
      req - request
      Returns:
      forward to index page.
      Throws:
      IOException
      jakarta.servlet.ServletException
    • doRunScript

      public void doRunScript(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, @QueryParameter("id") String id) throws IOException, jakarta.servlet.ServletException
      Display the screen to trigger a script. The source of the script get loaded from the filesystem and placed in the request to display it on the page before execution.
      Parameters:
      req - request
      rsp - response
      id - the id of the script to be executed
      Throws:
      IOException
      jakarta.servlet.ServletException
    • doTriggerScript

      public void doTriggerScript(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, @QueryParameter("id") String id, @QueryParameter("script") String scriptSrc, @QueryParameter("node") String node) throws IOException, jakarta.servlet.ServletException
      Trigger/run/execute the script on an agent and show the result/output. The request then gets forward to runScript.jelly (This is usually also where the request came from). The script passed to this method gets restored in the request again (and not loaded from the system). This way one is able to modify the script before execution and reuse the modified version for further executions.
      Parameters:
      req - request
      rsp - response
      id - the id of the script
      scriptSrc - the script code (groovy)
      node - the node to execute the code on.
      Throws:
      IOException
      jakarta.servlet.ServletException
    • doRun

      public void doRun(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, @QueryParameter(fixEmpty=true) String script, @QueryParameter(fixEmpty=true) String node, @QueryParameter(fixEmpty=true) String contentType) throws IOException, jakarta.servlet.ServletException
      Trigger/run/execute the script on an agent and directly forward the result/output to the response.
      Parameters:
      req - request
      rsp - response
      script - the script code (groovy)
      node - the node, to execute the code on, defaults to "(controller)"
      contentType - the contentType to use in the response, defaults to text/plain
      Throws:
      IOException
      jakarta.servlet.ServletException
    • doShowScript

      public void doShowScript(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, @AncestorInPath Item item, @QueryParameter("id") String id) throws IOException, jakarta.servlet.ServletException
      Loads the script by its name and forwards the request to "show.jelly".
      Parameters:
      req - request
      rsp - response
      id - the id of the script to be loaded in to the show view.
      Throws:
      IOException
      jakarta.servlet.ServletException
    • doEditScript

      public void doEditScript(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp, @QueryParameter("id") String id) throws IOException, jakarta.servlet.ServletException
      Loads the script by its name and forwards the request to "edit.jelly".
      Parameters:
      req - request
      rsp - response
      id - the id of the script to be loaded in to the edit view.
      Throws:
      IOException
      jakarta.servlet.ServletException
    • getSlaveAlias

      @Deprecated(since="381") public List<String> getSlaveAlias(Script script)
      Deprecated.
    • getComputerAliases

      public List<String> getComputerAliases(Script script)
      Gets the names of all configured computers, regardless whether they are online, including alias of ALL and ALL_AGENTS
      Returns:
      list with all computer names
    • getCatalogs

      public List<ScriptInfoCatalog<ScriptInfo>> getCatalogs()
      Gets the remote catalogs containing the available scripts for download.
      Returns:
      the catalog
    • getCatalogByName

      public ScriptInfoCatalog<ScriptInfo> getCatalogByName(String catalogName)
    • getCatalogInfoByName

      public CatalogInfo getCatalogInfoByName(String catalogName)
    • getScriptDirectory

      @Deprecated(since="380") public static File getScriptDirectory()
      Deprecated.
    • getScriptDirectory2

      public static Path getScriptDirectory2()
      returns the directory where the script files get stored
      Returns:
      the script directory
    • getScriptlerHomeDirectory

      @Deprecated(since="380") public static File getScriptlerHomeDirectory()
      Deprecated.
    • getScriptlerHomeDirectory2

      public static Path getScriptlerHomeDirectory2()