+ Include build number in target path. Default is false.
+
+ When true, the build number of the source project will be included in the target path.
+ This is particularly useful when the selector is specific and the value is a permalink, e.g. lastSuccessfulBuild.
+
+
diff --git a/src/main/webapp/help-flatten-optional.html b/src/main/webapp/help-flatten-optional.html
index 0035bc32..537407be 100644
--- a/src/main/webapp/help-flatten-optional.html
+++ b/src/main/webapp/help-flatten-optional.html
@@ -1,14 +1,23 @@
- Select "Flatten directories" to ignore the directory structure of the artifacts
+
+ Select "Flatten directories" to ignore the directory structure of the artifacts
in the source project and copy all matching artifacts directly into the specified
target directory. By default the artifacts are copied in the same directory
structure as the source project.
-
- Select "Optional" to allow this build to continue even if no build is found
+
+
+ Select "Optional" to allow this build to continue even if no build is found
matching the "Which build" condition selected above, the build's workspace does
not exist or is inaccessible, or no artifacts are found matching the specified
pattern. By default this build step fails the build if no artifacts are copied.
-
- Select "Fingerprint Artifacts" to automatically fingerprint all artifacts
+
+
+ Select "Fingerprint Artifacts" to automatically fingerprint all artifacts
that are copied as part of this build step.
+
+
+ Select "Include Build Number" to include the source build number in the target path.
+ When true, the build number of the source project will be included in the target path.
+ This is particularly useful when the selector is specific and the value is a permalink, e.g. lastSuccessfulBuild.
+
diff --git a/src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java b/src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
index 9d7697e0..717786f8 100644
--- a/src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
+++ b/src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
@@ -2249,7 +2249,47 @@ public void testIsValidVariableName() throws Exception {
assertFalse(CopyArtifact.isValidVariableName(" "));
assertFalse(CopyArtifact.isValidVariableName("=/?!\""));
}
-
+
+ @Test
+ public void testIncludeBuildNumberToTargetPath() throws Exception {
+ final Builder failureBuilder = new FailureBuilder();
+ final FreeStyleProject srcProject = createArtifactProject("SRC-PROJECT");
+
+ srcProject.getBuildersList().add(failureBuilder);
+ final FreeStyleBuild build1 = srcProject.scheduleBuild2(0).get();
+ rule.assertBuildStatus(Result.FAILURE, build1);
+
+ srcProject.getBuildersList().remove(failureBuilder);
+ final FreeStyleBuild build2 = srcProject.scheduleBuild2(0).get();
+ rule.assertBuildStatus(Result.SUCCESS, build2);
+
+ srcProject.getBuildersList().add(failureBuilder);
+ final FreeStyleBuild build3 = srcProject.scheduleBuild2(0).get();
+ rule.assertBuildStatus(Result.FAILURE, build3);
+
+ {
+ FreeStyleProject p = rule.createFreeStyleProject();
+ p.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(
+ srcProject.getFullName(),
+ null, // parameters
+ new SpecificBuildSelector("lastSuccessfulBuild"),
+ "", // filter
+ "", // excludes
+ "", // target
+ false, // flatten
+ false, // optional
+ true, // fingerprintArtifacts
+ "", // resultVariableSuffix
+ true // includeBuildNumberInTargetPath
+ ));
+ rule.assertBuildStatusSuccess(p.scheduleBuild2(0));
+
+ assertFalse(new FilePath(p.getWorkspace(), "1").exists());
+ assertTrue(new FilePath(p.getWorkspace(), "2").exists());
+ assertFalse(new FilePath(p.getWorkspace(), "3").exists());
+ }
+ }
+
@Test
public void testResultVariableSuffix() throws Exception {
FreeStyleProject srcProject = createArtifactProject("SRC-PROJECT1");
diff --git a/src/test/java/hudson/plugins/copyartifact/testutils/CopyArtifactUtil.java b/src/test/java/hudson/plugins/copyartifact/testutils/CopyArtifactUtil.java
index 91e82683..d4a7a95a 100644
--- a/src/test/java/hudson/plugins/copyartifact/testutils/CopyArtifactUtil.java
+++ b/src/test/java/hudson/plugins/copyartifact/testutils/CopyArtifactUtil.java
@@ -48,9 +48,14 @@ public static CopyArtifact createCopyArtifact(String projectName, String paramet
boolean flatten, boolean optional, boolean fingerprintArtifacts) {
return createCopyArtifact(projectName, parameters, selector, filter, excludes, target, flatten, optional, fingerprintArtifacts, null);
}
-
+
+ public static CopyArtifact createCopyArtifact(String projectName, String parameters, BuildSelector selector, String filter, String excludes, String target,
+ boolean flatten, boolean optional, boolean fingerprintArtifacts, String resultVariableSuffix) {
+ return createCopyArtifact(projectName, parameters, selector, filter, excludes, target, flatten, optional, fingerprintArtifacts, resultVariableSuffix, false);
+ }
+
public static CopyArtifact createCopyArtifact(String projectName, String parameters, BuildSelector selector, String filter, String excludes, String target,
- boolean flatten, boolean optional, boolean fingerprintArtifacts, String resultVariableSuffix) {
+ boolean flatten, boolean optional, boolean fingerprintArtifacts, String resultVariableSuffix, boolean includeBuildNumberInTargetPath) {
CopyArtifact copyArtifact = new CopyArtifact(projectName);
copyArtifact.setParameters(parameters);
copyArtifact.setSelector(selector);
@@ -61,6 +66,7 @@ public static CopyArtifact createCopyArtifact(String projectName, String paramet
copyArtifact.setOptional(optional);
copyArtifact.setFingerprintArtifacts(fingerprintArtifacts);
copyArtifact.setResultVariableSuffix(resultVariableSuffix);
+ copyArtifact.setIncludeBuildNumberInTargetPath(includeBuildNumberInTargetPath);
return copyArtifact;
}
}