提交 75363b74 编写于 作者: D dvrzalik

For remote managament it is useful to obtain system script output as plain text

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@13455 71c3de6d-444a-0410-be80-ed276b4c234a
上级 43272544
......@@ -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<TopLevelItem>, 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);
}
/**
......
<!--
Called from doScriptText() to display the execution result.
-->
<st:compress xmlns:j="jelly:core" xmlns:st="jelly:stapler">
<st:contentType value="text/plain;charset=UTF-8" />${output}</st:compress>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册