Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
8dc70fd6
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8dc70fd6
编写于
4月 04, 2015
作者:
O
Oliver Gondža
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1639 from olivergondza/JENKINS-26751
[FIXED JENKINS-26751] Do not run /script on offline slave
上级
a803dc1f
d8b1111c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
66 addition
and
27 deletion
+66
-27
core/src/main/java/hudson/util/RemotingDiagnostics.java
core/src/main/java/hudson/util/RemotingDiagnostics.java
+4
-1
core/src/main/java/jenkins/model/Jenkins.java
core/src/main/java/jenkins/model/Jenkins.java
+5
-0
core/src/main/resources/hudson/model/Computer/sidepanel.jelly
.../src/main/resources/hudson/model/Computer/sidepanel.jelly
+4
-2
core/src/main/resources/lib/hudson/scriptConsole.jelly
core/src/main/resources/lib/hudson/scriptConsole.jelly
+31
-24
test/src/test/java/jenkins/model/JenkinsTest.java
test/src/test/java/jenkins/model/JenkinsTest.java
+22
-0
未找到文件。
core/src/main/java/hudson/util/RemotingDiagnostics.java
浏览文件 @
8dc70fd6
...
...
@@ -34,15 +34,18 @@ import hudson.remoting.Future;
import
hudson.remoting.VirtualChannel
;
import
hudson.security.AccessControlled
;
import
jenkins.security.MasterToSlaveCallable
;
import
org.codehaus.groovy.control.CompilerConfiguration
;
import
org.codehaus.groovy.control.customizers.ImportCustomizer
;
import
org.kohsuke.stapler.StaplerRequest
;
import
org.kohsuke.stapler.StaplerResponse
;
import
org.kohsuke.stapler.WebMethod
;
import
javax.annotation.Nonnull
;
import
javax.management.JMException
;
import
javax.management.MBeanServer
;
import
javax.management.ObjectName
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
...
...
@@ -104,7 +107,7 @@ public final class RemotingDiagnostics {
/**
* Executes Groovy script remotely.
*/
public
static
String
executeGroovy
(
String
script
,
VirtualChannel
channel
)
throws
IOException
,
InterruptedException
{
public
static
String
executeGroovy
(
String
script
,
@Nonnull
VirtualChannel
channel
)
throws
IOException
,
InterruptedException
{
return
channel
.
call
(
new
Script
(
script
));
}
...
...
core/src/main/java/jenkins/model/Jenkins.java
浏览文件 @
8dc70fd6
...
...
@@ -3527,6 +3527,11 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
if
(!
"POST"
.
equals
(
req
.
getMethod
()))
{
throw
HttpResponses
.
error
(
HttpURLConnection
.
HTTP_BAD_METHOD
,
"requires POST"
);
}
if
(
channel
==
null
)
{
throw
HttpResponses
.
error
(
HttpURLConnection
.
HTTP_NOT_FOUND
,
"Node is offline"
);
}
try
{
req
.
setAttribute
(
"output"
,
RemotingDiagnostics
.
executeGroovy
(
text
,
channel
));
...
...
core/src/main/resources/hudson/model/Computer/sidepanel.jelly
浏览文件 @
8dc70fd6
...
...
@@ -36,7 +36,9 @@ THE SOFTWARE.
<l:task href="${rootURL}/${it.url}configure" icon="icon-setting icon-md" permission="${it.CONFIGURE}" title="${%Configure}"/>
<l:task href="${rootURL}/${it.url}builds" icon="icon-notepad icon-md" title="${%Build History}"/>
<l:task href="${rootURL}/${it.url}load-statistics" icon="icon-monitor icon-md" title="${%Load Statistics}"/>
<l:task href="${rootURL}/${it.url}script" icon="icon-terminal icon-md" permission="${app.RUN_SCRIPTS}" title="${%Script Console}"/>
<j:if test="${it.channel!=null}">
<l:task href="${rootURL}/${it.url}script" icon="icon-terminal icon-md" permission="${app.RUN_SCRIPTS}" title="${%Script Console}"/>
</j:if>
<st:include page="sidepanel2.jelly" optional="true" /><!-- hook for derived class to add more items -->
<t:actions />
</l:tasks>
...
...
@@ -45,4 +47,4 @@ THE SOFTWARE.
</j:forEach>
<t:executors computers="${h.singletonList(it)}" />
</l:side-panel>
</j:jelly>
\ No newline at end of file
</j:jelly>
core/src/main/resources/lib/hudson/scriptConsole.jelly
浏览文件 @
8dc70fd6
...
...
@@ -31,29 +31,36 @@ THE SOFTWARE.
<st:include page="sidepanel.jelly" />
<l:main-panel>
<h1>${%Script Console}</h1>
<p>
${%description}
</p>
<!-- this is where the example goes -->
<d:invokeBody />
<p>
${%description2}
</p>
<form action="script" method="post">
<textarea id="script" name="script" class="script">${request.getParameter('script')}</textarea>
<div align="right">
<f:submit value="${%Run}"/>
</div>
</form>
<st:adjunct includes="org.kohsuke.stapler.codemirror.mode.groovy.groovy"/>
<st:adjunct includes="org.kohsuke.stapler.codemirror.theme.default"/>
<j:if test="${output!=null}">
<h2>${%Result}</h2>
<pre><st:out value="${output}"/></pre>
</j:if>
<h1><img src="${imagesURL}/48x48/${it.icon}" width="48" height="48" alt=""/> ${%Script Console}</h1>
<j:choose>
<j:when test="${it.channel != null}">
<p>
${%description}
</p>
<!-- this is where the example goes -->
<d:invokeBody />
<p>
${%description2}
</p>
<form action="script" method="post">
<textarea id="script" name="script" class="script">${request.getParameter('script')}</textarea>
<div align="right">
<f:submit value="${%Run}"/>
</div>
</form>
<st:adjunct includes="org.kohsuke.stapler.codemirror.mode.groovy.groovy"/>
<st:adjunct includes="org.kohsuke.stapler.codemirror.theme.default"/>
<j:if test="${output!=null}">
<h2>${%Result}</h2>
<pre><st:out value="${output}"/></pre>
</j:if>
</j:when>
<j:otherwise>
${%It is not possible to run scripts when slave is offline.}
</j:otherwise>
</j:choose>
</l:main-panel>
</l:layout>
</j:jelly>
\ No newline at end of file
</j:jelly>
test/src/test/java/jenkins/model/JenkinsTest.java
浏览文件 @
8dc70fd6
...
...
@@ -23,6 +23,9 @@
*/
package
jenkins.model
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
...
...
@@ -31,7 +34,9 @@ import static org.junit.Assert.fail;
import
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException
;
import
com.gargoylesoftware.htmlunit.HttpMethod
;
import
com.gargoylesoftware.htmlunit.Page
;
import
com.gargoylesoftware.htmlunit.WebRequestSettings
;
import
com.gargoylesoftware.htmlunit.WebResponse
;
import
com.gargoylesoftware.htmlunit.html.HtmlForm
;
import
com.gargoylesoftware.htmlunit.html.HtmlPage
;
...
...
@@ -50,6 +55,7 @@ import hudson.security.GlobalMatrixAuthorizationStrategy;
import
hudson.security.LegacySecurityRealm
;
import
hudson.security.Permission
;
import
hudson.slaves.ComputerListener
;
import
hudson.slaves.DumbSlave
;
import
hudson.slaves.OfflineCause
;
import
hudson.util.FormValidation
;
...
...
@@ -427,4 +433,20 @@ public class JenkinsTest {
@TestExtension
(
value
=
"testComputerListenerNotifiedOnRestart"
)
public
static
final
ComputerListener
listenerMock
=
Mockito
.
mock
(
ComputerListener
.
class
);
@Test
public
void
runScriptOnOfflineComputer
()
throws
Exception
{
DumbSlave
slave
=
j
.
createSlave
();
URL
url
=
new
URL
(
j
.
getURL
(),
"computer/"
+
slave
.
getNodeName
()
+
"/scriptText?script=println(42)"
);
WebClient
wc
=
j
.
createWebClient
();
wc
.
setThrowExceptionOnFailingStatusCode
(
false
);
WebRequestSettings
req
=
new
WebRequestSettings
(
url
,
HttpMethod
.
POST
);
Page
page
=
wc
.
getPage
(
wc
.
addCrumb
(
req
));
WebResponse
rsp
=
page
.
getWebResponse
();
assertThat
(
rsp
.
getContentAsString
(),
containsString
(
"Node is offline"
));
assertThat
(
rsp
.
getStatusCode
(),
equalTo
(
404
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录