Package org.jenkinsci.plugins.scriptler
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)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class hudson.model.ManagementLink
ManagementLink.Category
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Field Summary
-
Fields inherited from class hudson.model.ManagementLink
LIST
-
-
Constructor Summary
Constructors Constructor Description ScriptlerManagement()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkAtLeastOneScriptlerPermission()
boolean
disableRemoteCatalog()
org.kohsuke.stapler.HttpResponse
doDownloadScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, String id, String catalogName)
Downloads a script from a catalog and imports it to the local system.void
doEditScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, String id)
Loads the script by its name and forwards the request to "edit.jelly".org.kohsuke.stapler.HttpResponse
doHardResetGit()
Triggers a hard reset on the git repoorg.kohsuke.stapler.HttpResponse
doRemoveScript(org.kohsuke.stapler.StaplerRequest res, org.kohsuke.stapler.StaplerResponse rsp, String id)
Removes a script from the config and filesystem.void
doRun(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, String script, String node, String contentType)
Trigger/run/execute the script on a slave and directly forward the result/output to the response.void
doRunScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, String id)
Display the screen to trigger a script.org.kohsuke.stapler.HttpResponse
doScriptAdd(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, String id, String name, String comment, String script, boolean nonAdministerUsing, boolean onlyMaster, String originCatalogName, String originId)
Saves a script snipplet as file to the system.org.kohsuke.stapler.HttpResponse
doScriptlerSettings(org.kohsuke.stapler.StaplerRequest res, org.kohsuke.stapler.StaplerResponse rsp, boolean disableRemoteCatalog)
save the scriptler 'global' settings (on settings screen, not global Jenkins config)void
doShowScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, Item item, String id)
Loads the script by its name and forwards the request to "show.jelly".void
doTriggerScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, String id, String scriptSrc, String node)
Trigger/run/execute the script on a slave and show the result/output.org.kohsuke.stapler.HttpResponse
doUploadScript(org.kohsuke.stapler.StaplerRequest req)
Uploads a script and stores it with the given filename to the configuration.ScriptInfoCatalog<? extends ScriptInfo>
getCatalogByName(String catalogName)
CatalogInfo
getCatalogInfoByName(String catalogName)
List<? extends ScriptInfoCatalog<ScriptInfo>>
getCatalogs()
Gets the remote catalogs containing the available scripts for download.ManagementLink.Category
getCategory()
ScriptlerConfiguration
getConfiguration()
String
getDescription()
String
getDisplayName()
String
getIconFileName()
MarkupFormatter
getMarkupFormatter()
static File
getScriptDirectory()
returns the directory where the script files get storedScriptlerManagement
getScriptler()
Permission
getScriptlerConfigure()
static File
getScriptlerHomeDirectory()
Permission
getScriptlerRunScripts()
List<String>
getSlaveAlias(Script script)
Gets the names of all configured slaves, regardless whether they are online, including alias of ALL and ALL_SLAVESString
getUrlName()
boolean
hasAtLeastOneScriptlerPermission()
-
Methods inherited from class hudson.model.ManagementLink
all, getBadge, getCategoryName, getRequiredPermission, getRequiresConfirmation, getRequiresPOST
-
-
-
-
Method Detail
-
getScriptlerRunScripts
public Permission getScriptlerRunScripts()
-
getScriptlerConfigure
public Permission getScriptlerConfigure()
-
hasAtLeastOneScriptlerPermission
public boolean hasAtLeastOneScriptlerPermission()
-
checkAtLeastOneScriptlerPermission
public void checkAtLeastOneScriptlerPermission()
-
getIconFileName
public String getIconFileName()
- Specified by:
getIconFileName
in interfaceAction
- Specified by:
getIconFileName
in classManagementLink
-
getCategory
@NonNull public ManagementLink.Category getCategory()
- Overrides:
getCategory
in classManagementLink
-
getUrlName
public String getUrlName()
- Specified by:
getUrlName
in interfaceAction
- Specified by:
getUrlName
in classManagementLink
-
disableRemoteCatalog
public boolean disableRemoteCatalog()
-
getDisplayName
public String getDisplayName()
- Specified by:
getDisplayName
in interfaceAction
- Specified by:
getDisplayName
in interfaceModelObject
-
getDescription
public String getDescription()
- Overrides:
getDescription
in classManagementLink
-
getScriptler
public ScriptlerManagement getScriptler()
-
getConfiguration
public ScriptlerConfiguration getConfiguration()
-
getMarkupFormatter
public MarkupFormatter getMarkupFormatter()
-
doScriptlerSettings
public org.kohsuke.stapler.HttpResponse doScriptlerSettings(org.kohsuke.stapler.StaplerRequest res, org.kohsuke.stapler.StaplerResponse rsp, @QueryParameter("disableRemoteCatalog") boolean disableRemoteCatalog) throws IOException
save the scriptler 'global' settings (on settings screen, not global Jenkins config)- Parameters:
res
-rsp
-disableRemoteCatalog
-- Returns:
- Throws:
IOException
-
doDownloadScript
public org.kohsuke.stapler.HttpResponse doDownloadScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse 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
- requestrsp
- responseid
- the id of the file to be downloadedcatalogName
- 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.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, @QueryParameter("id") String id, @QueryParameter("name") String name, @QueryParameter("comment") String comment, @QueryParameter("script") String script, @QueryParameter("nonAdministerUsing") boolean nonAdministerUsing, @QueryParameter("onlyMaster") boolean onlyMaster, String originCatalogName, String originId) throws IOException, javax.servlet.ServletException
Saves a script snipplet as file to the system.- Parameters:
req
- responsersp
- requestid
- the script id (fileName)name
- the name of the scriptcomment
- a commentscript
- script codenonAdministerUsing
- allow usage in Scriptler build steponlyMaster
- this script is only allwoed to run on the master nodeoriginCatalogName
- (optional) the name of the catalog the script is loaded/added fromoriginId
- (optional) the original id the script had at the catalog- Returns:
- forward to 'index'
- Throws:
IOException
javax.servlet.ServletException
-
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
http://jenkins.orga.com/scriptler.git
- Throws:
IOException
-
doRemoveScript
public org.kohsuke.stapler.HttpResponse doRemoveScript(org.kohsuke.stapler.StaplerRequest res, org.kohsuke.stapler.StaplerResponse rsp, @QueryParameter("id") String id) throws IOException
Removes a script from the config and filesystem.- Parameters:
res
- responsersp
- requestid
- the id of the file to be removed- Returns:
- forward to 'index'
- Throws:
IOException
-
doUploadScript
public org.kohsuke.stapler.HttpResponse doUploadScript(org.kohsuke.stapler.StaplerRequest req) throws IOException, javax.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
javax.servlet.ServletException
-
doRunScript
public void doRunScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, @QueryParameter("id") String id) throws IOException, javax.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
- requestrsp
- responseid
- the id of the script to be executed- Throws:
IOException
javax.servlet.ServletException
-
doTriggerScript
public void doTriggerScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, @QueryParameter("id") String id, @QueryParameter("script") String scriptSrc, @QueryParameter("node") String node) throws IOException, javax.servlet.ServletException
Trigger/run/execute the script on a slave and show the result/output. The request then gets forward torunScript.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
- requestrsp
- responseid
- the id of the scriptscriptSrc
- the script code (groovy)node
- the node, to execute the code on.- Throws:
IOException
javax.servlet.ServletException
-
doRun
public void doRun(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, @QueryParameter(fixEmpty=true) String script, @QueryParameter(fixEmpty=true) String node, @QueryParameter(fixEmpty=true) String contentType) throws IOException, javax.servlet.ServletException
Trigger/run/execute the script on a slave and directly forward the result/output to the response.- Parameters:
req
- requestrsp
- responsescript
- the script code (groovy)node
- the node, to execute the code on, defaults to "(master)"contentType
- the contentType to use in the response, defaults to text/plain- Throws:
IOException
javax.servlet.ServletException
-
doShowScript
public void doShowScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, @AncestorInPath Item item, @QueryParameter("id") String id) throws IOException, javax.servlet.ServletException
Loads the script by its name and forwards the request to "show.jelly".- Parameters:
req
- requestrsp
- responseid
- the id of the script to be loaded in to the show view.- Throws:
IOException
javax.servlet.ServletException
-
doEditScript
public void doEditScript(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, @QueryParameter("id") String id) throws IOException, javax.servlet.ServletException
Loads the script by its name and forwards the request to "edit.jelly".- Parameters:
req
- requestrsp
- responseid
- the id of the script to be loaded in to the edit view.- Throws:
IOException
javax.servlet.ServletException
-
getSlaveAlias
public List<String> getSlaveAlias(Script script)
Gets the names of all configured slaves, regardless whether they are online, including alias of ALL and ALL_SLAVES- Returns:
- list with all slave names
-
getCatalogs
public List<? extends ScriptInfoCatalog<ScriptInfo>> getCatalogs()
Gets the remote catalogs containing the available scripts for download.- Returns:
- the catalog
-
getCatalogByName
public ScriptInfoCatalog<? extends ScriptInfo> getCatalogByName(String catalogName)
-
getCatalogInfoByName
public CatalogInfo getCatalogInfoByName(String catalogName)
-
getScriptDirectory
public static File getScriptDirectory()
returns the directory where the script files get stored- Returns:
- the script directory
-
getScriptlerHomeDirectory
public static File getScriptlerHomeDirectory()
-
-