Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
roginluo
Jenkins
提交
15ba345b
J
Jenkins
项目概览
roginluo
/
Jenkins
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
Jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
15ba345b
编写于
10月 25, 2012
作者:
K
Kohsuke Kawaguchi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
inject delay as a parameter to make the parsing logic reusable
上级
9429452b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
72 addition
and
10 deletion
+72
-10
core/src/main/java/hudson/model/AbstractProject.java
core/src/main/java/hudson/model/AbstractProject.java
+10
-5
core/src/main/java/hudson/model/ParametersDefinitionProperty.java
.../main/java/hudson/model/ParametersDefinitionProperty.java
+10
-5
core/src/main/java/jenkins/util/TimeDuration.java
core/src/main/java/jenkins/util/TimeDuration.java
+52
-0
未找到文件。
core/src/main/java/hudson/model/AbstractProject.java
浏览文件 @
15ba345b
...
...
@@ -88,6 +88,7 @@ import jenkins.model.lazy.AbstractLazyLoadRunMap.Direction;
import
jenkins.scm.DefaultSCMCheckoutStrategyImpl
;
import
jenkins.scm.SCMCheckoutStrategy
;
import
jenkins.scm.SCMCheckoutStrategyDescriptor
;
import
jenkins.util.TimeDuration
;
import
net.sf.json.JSONObject
;
import
org.kohsuke.accmod.Restricted
;
import
org.kohsuke.accmod.restrictions.NoExternalUse
;
...
...
@@ -1710,20 +1711,21 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
/**
* Schedules a new build command.
*/
public
void
doBuild
(
StaplerRequest
req
,
StaplerResponse
rsp
)
throws
IOException
,
ServletException
{
public
void
doBuild
(
StaplerRequest
req
,
StaplerResponse
rsp
,
@QueryParameter
TimeDuration
delay
)
throws
IOException
,
ServletException
{
if
(
delay
==
null
)
delay
=
new
TimeDuration
(
getQuietPeriod
());
BuildAuthorizationToken
.
checkPermission
(
this
,
authToken
,
req
,
rsp
);
// if a build is parameterized, let that take over
ParametersDefinitionProperty
pp
=
getProperty
(
ParametersDefinitionProperty
.
class
);
if
(
pp
!=
null
)
{
pp
.
_doBuild
(
req
,
rsp
);
pp
.
_doBuild
(
req
,
rsp
,
delay
);
return
;
}
if
(!
isBuildable
())
throw
HttpResponses
.
error
(
SC_INTERNAL_SERVER_ERROR
,
new
IOException
(
getFullName
()+
" is not buildable"
));
Jenkins
.
getInstance
().
getQueue
().
schedule
(
this
,
getDelay
(
req
),
getBuildCause
(
req
));
Jenkins
.
getInstance
().
getQueue
().
schedule
(
this
,
(
int
)
delay
.
getTime
(
),
getBuildCause
(
req
));
rsp
.
forwardToPreviousPage
(
req
);
}
...
...
@@ -1744,6 +1746,9 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
/**
* Computes the delay by taking the default value and the override in the request parameter into the account.
*
* @deprecated as of 1.488
* Inject {@link TimeDuration}.
*/
public
int
getDelay
(
StaplerRequest
req
)
throws
ServletException
{
String
delay
=
req
.
getParameter
(
"delay"
);
...
...
@@ -1763,12 +1768,12 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
* Supports build trigger with parameters via an HTTP GET or POST.
* Currently only String parameters are supported.
*/
public
void
doBuildWithParameters
(
StaplerRequest
req
,
StaplerResponse
rsp
)
throws
IOException
,
ServletException
{
public
void
doBuildWithParameters
(
StaplerRequest
req
,
StaplerResponse
rsp
,
@QueryParameter
TimeDuration
delay
)
throws
IOException
,
ServletException
{
BuildAuthorizationToken
.
checkPermission
(
this
,
authToken
,
req
,
rsp
);
ParametersDefinitionProperty
pp
=
getProperty
(
ParametersDefinitionProperty
.
class
);
if
(
pp
!=
null
)
{
pp
.
buildWithParameters
(
req
,
rsp
);
pp
.
buildWithParameters
(
req
,
rsp
,
delay
);
}
else
{
throw
new
IllegalStateException
(
"This build is not parameterized!"
);
}
...
...
core/src/main/java/hudson/model/ParametersDefinitionProperty.java
浏览文件 @
15ba345b
...
...
@@ -35,9 +35,11 @@ import java.util.AbstractList;
import
javax.servlet.ServletException
;
import
jenkins.model.Jenkins
;
import
jenkins.util.TimeDuration
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.kohsuke.stapler.QueryParameter
;
import
org.kohsuke.stapler.StaplerRequest
;
import
org.kohsuke.stapler.StaplerResponse
;
import
org.kohsuke.stapler.export.Exported
;
...
...
@@ -104,14 +106,16 @@ public class ParametersDefinitionProperty extends JobProperty<AbstractProject<?,
* Interprets the form submission and schedules a build for a parameterized job.
*
* <p>
* This method is supposed to be invoked from {@link AbstractProject#doBuild(StaplerRequest, StaplerResponse)}.
* This method is supposed to be invoked from {@link AbstractProject#doBuild(StaplerRequest, StaplerResponse
, TimeDuration
)}.
*/
public
void
_doBuild
(
StaplerRequest
req
,
StaplerResponse
rsp
)
throws
IOException
,
ServletException
{
public
void
_doBuild
(
StaplerRequest
req
,
StaplerResponse
rsp
,
@QueryParameter
TimeDuration
delay
)
throws
IOException
,
ServletException
{
if
(!
req
.
getMethod
().
equals
(
"POST"
))
{
// show the parameter entry form.
req
.
getView
(
this
,
"index.jelly"
).
forward
(
req
,
rsp
);
return
;
}
if
(
delay
==
null
)
delay
=
new
TimeDuration
(
owner
.
getQuietPeriod
());
List
<
ParameterValue
>
values
=
new
ArrayList
<
ParameterValue
>();
...
...
@@ -130,13 +134,13 @@ public class ParametersDefinitionProperty extends JobProperty<AbstractProject<?,
}
Jenkins
.
getInstance
().
getQueue
().
schedule
(
owner
,
owner
.
getDelay
(
req
),
new
ParametersAction
(
values
),
new
CauseAction
(
new
Cause
.
UserIdCause
()));
owner
,
delay
.
getTime
(
),
new
ParametersAction
(
values
),
new
CauseAction
(
new
Cause
.
UserIdCause
()));
// send the user back to the job top page.
rsp
.
sendRedirect
(
"."
);
}
public
void
buildWithParameters
(
StaplerRequest
req
,
StaplerResponse
rsp
)
throws
IOException
,
ServletException
{
public
void
buildWithParameters
(
StaplerRequest
req
,
StaplerResponse
rsp
,
TimeDuration
delay
)
throws
IOException
,
ServletException
{
List
<
ParameterValue
>
values
=
new
ArrayList
<
ParameterValue
>();
for
(
ParameterDefinition
d:
parameterDefinitions
)
{
ParameterValue
value
=
d
.
createValue
(
req
);
...
...
@@ -144,9 +148,10 @@ public class ParametersDefinitionProperty extends JobProperty<AbstractProject<?,
values
.
add
(
value
);
}
}
if
(
delay
==
null
)
delay
=
new
TimeDuration
(
owner
.
getQuietPeriod
());
Jenkins
.
getInstance
().
getQueue
().
schedule
(
owner
,
owner
.
getDelay
(
req
),
new
ParametersAction
(
values
),
owner
.
getBuildCause
(
req
));
owner
,
delay
.
getTime
(
),
new
ParametersAction
(
values
),
owner
.
getBuildCause
(
req
));
if
(
requestWantsJson
(
req
))
{
rsp
.
setContentType
(
"application/json"
);
...
...
core/src/main/java/jenkins/util/TimeDuration.java
0 → 100644
浏览文件 @
15ba345b
package
jenkins.util
;
import
org.apache.commons.beanutils.Converter
;
import
java.util.concurrent.TimeUnit
;
/**
* Represents a length of something, like "3 seconds"
*
* This supports parameter injection, such as via {@link QueryParameter}.
*
* @author Kohsuke Kawaguchi
* @since 1.489
*/
public
class
TimeDuration
{
private
final
long
millis
;
public
TimeDuration
(
long
millis
)
{
this
.
millis
=
millis
;
}
public
int
getTime
()
{
return
(
int
)
millis
;
}
public
long
getTimeInMillis
()
{
return
millis
;
}
public
long
as
(
TimeUnit
t
)
{
return
t
.
convert
(
millis
,
TimeUnit
.
MILLISECONDS
);
}
public
static
class
StaplerConverterImpl
implements
Converter
{
public
Object
convert
(
Class
type
,
Object
value
)
{
if
(
value
==
null
)
return
null
;
if
(
value
instanceof
String
)
{
String
delay
=
(
String
)
value
;
try
{
// TODO: more unit handling
if
(
delay
.
endsWith
(
"sec"
))
delay
=
delay
.
substring
(
0
,
delay
.
length
()-
3
);
if
(
delay
.
endsWith
(
"secs"
))
delay
=
delay
.
substring
(
0
,
delay
.
length
()-
4
);
return
new
TimeDuration
(
Long
.
parseLong
(
delay
));
}
catch
(
NumberFormatException
e
)
{
throw
new
IllegalArgumentException
(
"Invalid time duration value: "
+
delay
);
}
}
throw
new
UnsupportedOperationException
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录