Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FIY695
jenkins
提交
6df89e33
J
jenkins
项目概览
FIY695
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
6df89e33
编写于
4月 21, 2014
作者:
D
Daniel Beck
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FIXED JENKINS-22699] Add option to archive only if successful
上级
dcfeaf3c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
49 addition
and
3 deletion
+49
-3
core/src/main/java/hudson/tasks/ArtifactArchiver.java
core/src/main/java/hudson/tasks/ArtifactArchiver.java
+21
-2
core/src/main/resources/hudson/tasks/ArtifactArchiver/config.jelly
...main/resources/hudson/tasks/ArtifactArchiver/config.jelly
+3
-0
core/src/main/resources/hudson/tasks/ArtifactArchiver/config.properties
...resources/hudson/tasks/ArtifactArchiver/config.properties
+2
-1
core/src/main/resources/hudson/tasks/Messages.properties
core/src/main/resources/hudson/tasks/Messages.properties
+1
-0
test/src/test/java/hudson/tasks/ArtifactArchiverTest.java
test/src/test/java/hudson/tasks/ArtifactArchiverTest.java
+22
-0
未找到文件。
core/src/main/java/hudson/tasks/ArtifactArchiver.java
浏览文件 @
6df89e33
...
...
@@ -74,16 +74,26 @@ public class ArtifactArchiver extends Recorder {
@Nonnull
private
Boolean
allowEmptyArchive
;
/**
* Archive only if build is successful, skip archiving on failed builds.
*/
private
boolean
onlyIfSuccessful
;
public
ArtifactArchiver
(
String
artifacts
,
String
excludes
,
boolean
latestOnly
)
{
this
(
artifacts
,
excludes
,
latestOnly
,
false
);
this
(
artifacts
,
excludes
,
latestOnly
,
false
,
false
);
}
@DataBoundConstructor
public
ArtifactArchiver
(
String
artifacts
,
String
excludes
,
boolean
latestOnly
,
boolean
allowEmptyArchive
)
{
this
(
artifacts
,
excludes
,
latestOnly
,
allowEmptyArchive
,
false
);
}
@DataBoundConstructor
public
ArtifactArchiver
(
String
artifacts
,
String
excludes
,
boolean
latestOnly
,
boolean
allowEmptyArchive
,
boolean
onlyIfSuccessful
)
{
this
.
artifacts
=
artifacts
.
trim
();
this
.
excludes
=
Util
.
fixEmptyAndTrim
(
excludes
);
this
.
latestOnly
=
latestOnly
;
this
.
allowEmptyArchive
=
allowEmptyArchive
;
this
.
onlyIfSuccessful
=
onlyIfSuccessful
;
}
// Backwards compatibility for older builds
...
...
@@ -106,6 +116,10 @@ public class ArtifactArchiver extends Recorder {
return
latestOnly
;
}
public
boolean
isOnlyIfSuccessful
()
{
return
onlyIfSuccessful
;
}
public
boolean
getAllowEmptyArchive
()
{
return
allowEmptyArchive
;
}
...
...
@@ -126,6 +140,11 @@ public class ArtifactArchiver extends Recorder {
return
true
;
}
if
(
build
.
getResult
().
isWorseThan
(
Result
.
UNSTABLE
)
&&
onlyIfSuccessful
)
{
listener
.
getLogger
().
println
(
Messages
.
ArtifactArchiver_SkipBecauseOnlyIfSuccessful
());
return
true
;
}
listener
.
getLogger
().
println
(
Messages
.
ArtifactArchiver_ARCHIVING_ARTIFACTS
());
try
{
FilePath
ws
=
build
.
getWorkspace
();
...
...
core/src/main/resources/hudson/tasks/ArtifactArchiver/config.jelly
浏览文件 @
6df89e33
...
...
@@ -37,5 +37,8 @@ THE SOFTWARE.
<f:entry field="allowEmptyArchive" >
<f:checkbox title="${%allowEmptyArchive}"/>
</f:entry>
<f:entry field="onlyIfSuccessful" >
<f:checkbox title="${%onlyIfSuccessful}"/>
</f:entry>
</f:advanced>
</j:jelly>
\ No newline at end of file
core/src/main/resources/hudson/tasks/ArtifactArchiver/config.properties
浏览文件 @
6df89e33
...
...
@@ -21,4 +21,5 @@
# THE SOFTWARE.
lastBuildOnly
=
Discard all but the last successful/stable artifact to save disk space
allowEmptyArchive
=
Do not fail build if archiving returns nothing
\ No newline at end of file
allowEmptyArchive
=
Do not fail build if archiving returns nothing
onlyIfSuccessful
=
Archive artifacts only if build is successful
\ No newline at end of file
core/src/main/resources/hudson/tasks/Messages.properties
浏览文件 @
6df89e33
...
...
@@ -31,6 +31,7 @@ Ant.ProjectConfigNeeded= Maybe you need to configure the job to choose one of yo
ArtifactArchiver.ARCHIVING_ARTIFACTS
=
Archiving artifacts
ArtifactArchiver.DeletingOld
=
Deleting old artifacts from {0}
ArtifactArchiver.DisplayName
=
Archive the artifacts
ArtifactArchiver.SkipBecauseOnlyIfSuccessful
=
Skipped archiving because build is not successful
ArtifactArchiver.FailedToArchive
=
Failed to archive artifacts: {0}
ArtifactArchiver.NoIncludes
=
\
No artifacts are configured for archiving.
\n\
...
...
test/src/test/java/hudson/tasks/ArtifactArchiverTest.java
浏览文件 @
6df89e33
...
...
@@ -24,6 +24,7 @@
package
hudson.tasks
;
import
hudson.AbortException
;
import
hudson.FilePath
;
import
hudson.Launcher
;
import
hudson.model.AbstractBuild
;
...
...
@@ -253,4 +254,25 @@ public class ArtifactArchiverTest {
}
}
static
class
CreateArtifactAndFail
extends
TestBuilder
{
public
boolean
perform
(
AbstractBuild
<?,?>
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
IOException
,
InterruptedException
{
build
.
getWorkspace
().
child
(
"f"
).
write
(
"content"
,
"UTF-8"
);
throw
new
AbortException
(
"failing the build"
);
}
}
@Test
@Bug
(
22698
)
public
void
testArchivingSkippedWhenOnlyIfSuccessfulChecked
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
();
project
.
getPublishersList
().
replaceBy
(
Collections
.
singleton
(
new
ArtifactArchiver
(
"f"
,
""
,
false
,
false
,
false
)));
project
.
getBuildersList
().
replaceBy
(
Collections
.
singleton
(
new
CreateArtifactAndFail
()));
assertEquals
(
Result
.
FAILURE
,
build
(
project
));
assertTrue
(
project
.
getBuildByNumber
(
1
).
getHasArtifacts
());
project
.
getPublishersList
().
replaceBy
(
Collections
.
singleton
(
new
ArtifactArchiver
(
"f"
,
""
,
false
,
false
,
true
)));
assertEquals
(
Result
.
FAILURE
,
build
(
project
));
assertTrue
(
project
.
getBuildByNumber
(
1
).
getHasArtifacts
());
assertFalse
(
project
.
getBuildByNumber
(
2
).
getHasArtifacts
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录