Skip to content
Permalink
Browse files

[JENKINS-26694] Added a test to reproduce JENKINS-26694.

  • Loading branch information...
ikedam committed Feb 14, 2015
1 parent 47e05f2 commit abd5a3067a3a0769115cd73716978545ff7892bc
Showing with 50 additions and 0 deletions.
  1. +50 −0 src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
@@ -71,6 +71,8 @@
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
@@ -1132,6 +1134,54 @@ public void testSpecificBuildSelectorWithParameterFilter() throws Exception {
assertFile(false, "foo.txt", b);
}

/**
* Test filtering on parameters works to copy from workflow jobs.
*/
@Bug(26694)
public void testFilterByParametersForWorkflow() throws Exception {
WorkflowJob copiee = jenkins.createProject(WorkflowJob.class, createUniqueProjectName());
copiee.addProperty(new ParametersDefinitionProperty(
new StringParameterDefinition("PARAM", "")
));
copiee.setDefinition(new CpsFlowDefinition(
"node {"
+ "writeFile text: \"${PARAM}\", file:'artifact.txt';"
+ "archive includes:'artifact.txt';"
+ "}",
true
));

FreeStyleProject copier = createFreeStyleProject();
copier.addProperty(new ParametersDefinitionProperty(
new StringParameterDefinition("PARAM_TO_COPY", "")
));
copier.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(
copiee.getFullName(),
"PARAM=${PARAM_TO_COPY}",
new LastCompletedBuildSelector(),
"artifact.txt",
"",
false,
false
));

// #1: PARAM=foo
assertBuildStatusSuccess(copiee.scheduleBuild2(0, new ParametersAction(
new StringParameterValue("PARAM", "foo")
)));
// #2: PARAM=bar
assertBuildStatusSuccess(copiee.scheduleBuild2(0, new ParametersAction(
new StringParameterValue("PARAM", "bar")
)));

FreeStyleBuild build = copier.scheduleBuild2(0, new UserCause(), new ParametersAction(
new StringParameterValue("PARAM_TO_COPY", "foo")
)).get();
assertBuildStatusSuccess(build);

assertEquals("foo", build.getWorkspace().child("artifact.txt").readToString());
}

// Verify BuildSelector defaults to false
public void testBuildSelectorDefault() {
assertFalse(new BuildSelector() { }.isSelectable(null, null));

0 comments on commit abd5a30

Please sign in to comment.
You can’t perform that action at this time.