Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
6327e265
J
jenkins
项目概览
LinuxSuRen
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
6327e265
编写于
4月 26, 2013
作者:
K
Kohsuke Kawaguchi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added the set-build-parameter command.
上级
0adc32a7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
123 addition
and
0 deletion
+123
-0
changelog.html
changelog.html
+2
-0
core/src/main/java/hudson/cli/SetBuildParameterCommand.java
core/src/main/java/hudson/cli/SetBuildParameterCommand.java
+49
-0
core/src/main/java/hudson/model/ParametersAction.java
core/src/main/java/hudson/model/ParametersAction.java
+24
-0
core/src/main/resources/hudson/cli/Messages.properties
core/src/main/resources/hudson/cli/Messages.properties
+1
-0
test/src/test/groovy/hudson/cli/SetBuildParameterCommandTest.groovy
...est/groovy/hudson/cli/SetBuildParameterCommandTest.groovy
+47
-0
未找到文件。
changelog.html
浏览文件 @
6327e265
...
...
@@ -55,6 +55,8 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. -->
<div
id=
"trunk"
style=
"display:none"
>
<!--=TRUNK-BEGIN=-->
<ul
class=
image
>
<li
class=
rfe
>
Added a new
<tt>
set-build-parameter
</tt>
command that can update a build variable from within a build.
<li
class=
rfe
>
Can use
<code>
-Dhudson.udp=-1
</code>
to disable UDP broadcast without showing an ugly exception.
<li
class=
bug
>
...
...
core/src/main/java/hudson/cli/SetBuildParameterCommand.java
0 → 100644
浏览文件 @
6327e265
package
hudson.cli
;
import
hudson.Extension
;
import
hudson.model.ParametersAction
;
import
hudson.model.Run
;
import
hudson.model.StringParameterValue
;
import
org.kohsuke.args4j.Argument
;
import
java.util.Collections
;
/**
* Used from the build to update the build variable.
*
* This allows one build step to affect the environment variables seen by later build steps.
*
* @author Kohsuke Kawaguchi
* @since 1.514
*/
@Extension
public
class
SetBuildParameterCommand
extends
CommandDuringBuild
{
@Argument
(
index
=
0
,
required
=
true
,
usage
=
"Name of the build variable"
)
public
String
name
;
@Argument
(
index
=
1
,
required
=
true
,
usage
=
"Value of the build variable"
)
public
String
value
;
@Override
public
String
getShortDescription
()
{
return
Messages
.
SetBuildParameterCommand_ShortDescription
();
}
@Override
protected
int
run
()
throws
Exception
{
Run
r
=
getCurrentlyBuilding
();
StringParameterValue
p
=
new
StringParameterValue
(
name
,
value
);
ParametersAction
a
=
r
.
getAction
(
ParametersAction
.
class
);
if
(
a
!=
null
)
{
ParametersAction
b
=
a
.
createUpdated
(
Collections
.
singleton
(
p
));
r
.
addAction
(
b
);
r
.
getActions
().
remove
(
a
);
}
else
{
r
.
addAction
(
new
ParametersAction
(
p
));
}
return
0
;
}
}
core/src/main/java/hudson/model/ParametersAction.java
浏览文件 @
6327e265
...
...
@@ -36,6 +36,7 @@ import hudson.util.VariableResolver;
import
org.kohsuke.stapler.export.Exported
;
import
org.kohsuke.stapler.export.ExportedBean
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
...
...
@@ -159,6 +160,29 @@ public class ParametersAction implements Action, Iterable<ParameterValue>, Queue
}
}
/**
* Creates a new {@link ParametersAction} that contains all the parameters in this action
* with the overrides / new values given as parameters.
*/
public
ParametersAction
createUpdated
(
Collection
<?
extends
ParameterValue
>
newValues
)
{
List
<
ParameterValue
>
r
=
new
ArrayList
<
ParameterValue
>();
Set
<
String
>
names
=
new
HashSet
<
String
>();
for
(
ParameterValue
v
:
newValues
)
{
names
.
add
(
v
.
name
);
}
for
(
Iterator
<
ParameterValue
>
itr
=
parameters
.
iterator
();
itr
.
hasNext
();
)
{
ParameterValue
v
=
itr
.
next
();
if
(!
names
.
contains
(
v
.
getName
()))
r
.
add
(
v
);
}
r
.
addAll
(
newValues
);
return
new
ParametersAction
(
r
);
}
private
Object
readResolve
()
{
if
(
build
!=
null
)
OldDataMonitor
.
report
(
build
,
"1.283"
);
...
...
core/src/main/resources/hudson/cli/Messages.properties
浏览文件 @
6327e265
...
...
@@ -37,6 +37,7 @@ MailCommand.ShortDescription=\
Reads stdin and sends that out as an e-mail.
SetBuildDescriptionCommand.ShortDescription
=
\
Sets the description of a build.
SetBuildParameterCommand.ShortDescription
=
Update/set the build parameter of the current build in progress
SetBuildResultCommand.ShortDescription
=
\
Sets the result of the current build. Works only if invoked from within a build.
VersionCommand.ShortDescription
=
\
...
...
test/src/test/groovy/hudson/cli/SetBuildParameterCommandTest.groovy
0 → 100644
浏览文件 @
6327e265
package
hudson.cli
import
hudson.Launcher
import
hudson.model.AbstractBuild
import
hudson.model.BuildListener
import
hudson.model.ParametersAction
import
hudson.tasks.Shell
import
jenkins.model.JenkinsLocationConfiguration
import
org.junit.Assert
import
org.junit.Rule
import
org.junit.Test
import
org.jvnet.hudson.test.JenkinsRule
import
org.jvnet.hudson.test.TestBuilder
/**
* @author Kohsuke Kawaguchi
*/
public
class
SetBuildParameterCommandTest
{
@Rule
public
JenkinsRule
j
=
new
JenkinsRule
();
@Test
public
void
cli
()
{
JenkinsLocationConfiguration
.
get
().
url
=
j
.
URL
;
def
p
=
j
.
createFreeStyleProject
();
p
.
buildersList
.
add
(
new
TestBuilder
()
{
@Override
boolean
perform
(
AbstractBuild
<?,
?>
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
InterruptedException
,
IOException
{
def
jar
=
j
.
jenkins
.
servletContext
.
getResource
(
"/WEB-INF/jenkins-cli.jar"
)
build
.
workspace
.
child
(
"cli.jar"
).
copyFrom
(
jar
);
return
true
;
}
});
p
.
buildersList
.
add
(
new
Shell
(
"java -jar cli.jar set-build-parameter a b"
))
p
.
buildersList
.
add
(
new
Shell
(
"java -jar cli.jar set-build-parameter a x"
))
p
.
buildersList
.
add
(
new
Shell
(
"java -jar cli.jar set-build-parameter b y"
))
def
r
=
[:];
def
b
=
j
.
assertBuildStatusSuccess
(
p
.
scheduleBuild2
(
0
))
b
.
getAction
(
ParametersAction
.
class
).
parameters
.
each
{
v
->
r
[
v
.
name
]=
v
.
value
}
assert
r
.
equals
([
"a"
:
"x"
,
"b"
:
"y"
]);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录