diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index dacaea1740650723e126701c5c44236b495e5bc1..03a24ae1f819b759aa2cd04a38a42dbe5b498c8c 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -143,6 +143,7 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import java.util.regex.Pattern; import java.nio.charset.Charset; +import javax.servlet.RequestDispatcher; /** * Root object of the system. @@ -2188,21 +2189,32 @@ public final class Hudson extends View implements ItemGroup, Node, * For system diagnostics. * Run arbitrary Groovy script. */ - public void doScript( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { + public void doScript(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { + doScript(req, rsp, req.getView(this, "_script.jelly")); + } + + /** + * Run arbitrary Groovy script and return result as plain text. + */ + public void doScriptText(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { + doScript(req, rsp, req.getView(this, "_scriptText.jelly")); + } + + private void doScript(StaplerRequest req, StaplerResponse rsp, RequestDispatcher view) throws IOException, ServletException { // ability to run arbitrary script is dangerous checkPermission(ADMINISTER); String text = req.getParameter("script"); - if(text!=null) { + if (text != null) { try { req.setAttribute("output", - RemotingDiagnostics.executeGroovy(text, MasterComputer.localChannel)); + RemotingDiagnostics.executeGroovy(text, MasterComputer.localChannel)); } catch (InterruptedException e) { throw new ServletException(e); } } - req.getView(this,"_script.jelly").forward(req,rsp); + view.forward(req, rsp); } /** diff --git a/core/src/main/resources/hudson/model/Hudson/_scriptText.jelly b/core/src/main/resources/hudson/model/Hudson/_scriptText.jelly new file mode 100644 index 0000000000000000000000000000000000000000..6d0a92ede696fcce35a11129c79adffc2e597281 --- /dev/null +++ b/core/src/main/resources/hudson/model/Hudson/_scriptText.jelly @@ -0,0 +1,5 @@ + + +${output} \ No newline at end of file