Skip to content

Commit

Permalink
[FIXED JENKINS-23084] Support absolute paths in "Parameters from prop…
Browse files Browse the repository at this point in the history
…erties file".
  • Loading branch information
ikedam committed May 18, 2014
1 parent 6ffdde8 commit c9f8bf5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
@@ -1,5 +1,6 @@
<div>
Comma seperated list of paths to file(s) in the workspace that contains the parameters for the new project.
Comma seperated list of absolute or relative paths to file(s) that contains the parameters for the new project.
Relative paths are originated from the workspace.
The file should have KEY=value pairs, one per line (Java properties file format).
Backslashes are used for escaping, so use "\\" for a single backslash.
<p/>
Expand Down
Expand Up @@ -23,6 +23,7 @@
*/
package hudson.plugins.parameterizedtrigger.test;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
Expand Down Expand Up @@ -53,6 +54,7 @@
import hudson.tasks.Builder;
import hudson.util.FormValidation;

import org.apache.commons.io.FileUtils;
import org.jvnet.hudson.test.CaptureEnvironmentBuilder;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
Expand Down Expand Up @@ -747,4 +749,47 @@ public void testMatrixBuildsConfiguration() throws Exception {
assertEquals("axis1=value1", p.getCombinationFilter());
assertTrue(p.isOnlyExactRuns());
}

public void testAbsolutePath() throws Exception {
FreeStyleProject downstream = createFreeStyleProject();

FreeStyleProject upstream = createFreeStyleProject();

File absoluteFile = new File(jenkins.getRootDir(), "properties.txt");
FileUtils.writeStringToFile(absoluteFile, "absolute_param=value1");

File relativeFile = new File(new File(jenkins.getWorkspaceFor(upstream).getRemote()), "../properties.txt");
FileUtils.writeStringToFile(relativeFile, "relative_param1=value2");

upstream.getBuildersList().add(new WriteFileBuilder("properties.txt", "relative_param2=value3"));
upstream.getPublishersList().add(new BuildTrigger(
new BuildTriggerConfig(downstream.getFullName(), ResultCondition.SUCCESS, true, Arrays.<AbstractBuildParameters>asList(
new FileBuildParameters(String.format("%s,../properties.txt,properties.txt", absoluteFile.getAbsolutePath()))
))
));

jenkins.rebuildDependencyGraph();

assertBuildStatusSuccess(upstream.scheduleBuild2(0));
waitUntilNoActivity();

FreeStyleBuild build = downstream.getLastBuild();
assertNotNull(build);
assertEquals("value1", getStringParameterValue(build, "absolute_param"));
assertEquals("value2", getStringParameterValue(build, "relative_param1"));
assertEquals("value3", getStringParameterValue(build, "relative_param2"));
}

/**
* Builder that removes a workspace.
*/
private static class WorkspaceRemoveBuilder extends Builder {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException, IOException
{
build.getWorkspace().deleteRecursive();
return true;
}
}
}

0 comments on commit c9f8bf5

Please sign in to comment.