Skip to content

Commit

Permalink
[JENKINS-26694] Added a test to reproduce JENKINS-26694.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedam committed Feb 14, 2015
1 parent 47e05f2 commit abd5a30
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit abd5a30

Please sign in to comment.