Skip to content
Permalink
Browse files

[FIXED JENKINS-16462] Run parameters do not support folders.

  • Loading branch information
jglick committed Jan 24, 2013
1 parent 1979302 commit de9002b3985cfa11971bf51137179464d6b0fa20
@@ -58,6 +58,9 @@
<li class=bug>
Bogus “Build Record Root Directory” inadequately diagnosed.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16457">issue 16457</a>)
<li class=bug>
Run parameters do not support folders.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-16462">issue 16462</a>)
</ul>
</div><!--=TRUNK-END=-->

@@ -36,6 +36,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.CheckForNull;

/**
* Data representation of the auto-completion candidates.
@@ -86,7 +87,7 @@ public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object o)
* @param container
* The nearby contextual {@link ItemGroup} to resolve relative job names from.
*/
public static <T extends Item> AutoCompletionCandidates ofJobNames(final Class<T> type, final String value, Item self, ItemGroup container) {
public static <T extends Item> AutoCompletionCandidates ofJobNames(final Class<T> type, final String value, @CheckForNull Item self, ItemGroup container) {
if (self==container)
container = self.getParent();

@@ -101,7 +101,6 @@
import jenkins.model.JenkinsLocationConfiguration;
import jenkins.util.io.OnMaster;
import net.sf.json.JSONObject;
import org.apache.commons.io.input.NullInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.jelly.XMLOutput;
import org.kohsuke.accmod.Restricted;
@@ -2028,7 +2027,7 @@ public final EnvVars getCharacteristicEnvVars() {
}

public String getExternalizableId() {
return project.getName() + "#" + getNumber();
return project.getFullName() + "#" + getNumber();
}

public static Run<?,?> fromExternalizableId(String id) {
@@ -2039,7 +2038,7 @@ public String getExternalizableId() {
String jobName = id.substring(0, hash);
int number = Integer.parseInt(id.substring(hash + 1));

Job<?,?> job = (Job<?,?>) Jenkins.getInstance().getItem(jobName);
Job<?,?> job = Jenkins.getInstance().getItemByFullName(jobName, Job.class);
return job.getBuildByNumber(number);
}

@@ -30,6 +30,7 @@
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.export.Exported;
import hudson.Extension;
import org.kohsuke.stapler.QueryParameter;

public class RunParameterDefinition extends SimpleParameterDefinition {

@@ -65,7 +66,7 @@ public String getProjectName() {
}

public Job getProject() {
return (Job) Jenkins.getInstance().getItem(projectName);
return Jenkins.getInstance().getItemByFullName(projectName, Job.class);
}

@Extension
@@ -84,6 +85,11 @@ public String getHelpFile() {
public ParameterDefinition newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return req.bindJSON(RunParameterDefinition.class, formData);
}

public AutoCompletionCandidates doAutoCompleteProjectName(@QueryParameter String value) {
return AutoCompletionCandidates.ofJobNames(Job.class, value, null, Jenkins.getInstance());
}

}

@Override
@@ -30,11 +30,7 @@ THE SOFTWARE.
<f:textbox name="parameter.name" value="${instance.name}" />
</f:entry>
<f:entry title="${%Project}" help="/help/parameter/run-project.html">
<select name="parameter.projectName">
<j:forEach var="project" items="${app.items}">
<f:option selected="${instance.project==project}">${project.displayName}</f:option>
</j:forEach>
</select>
<f:textbox name="parameter.projectName" value="${instance.projectName}" autoCompleteField="projectName"/>
</f:entry>
<f:entry title="${%Description}" help="/help/parameter/description.html">
<f:textarea name="parameter.description" value="${instance.description}" />
@@ -0,0 +1,66 @@
/*
* The MIT License
*
* Copyright 2013 Jesse Glick.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.model;

import hudson.EnvVars;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockFolder;

public class RunParameterDefinitionTest {

@Rule public JenkinsRule j = new JenkinsRule();

@Bug(16462)
@Test public void inFolders() throws Exception {
MockFolder dir = j.createFolder("dir");
MockFolder subdir = dir.createProject(MockFolder.class, "sub dir");
FreeStyleProject p = subdir.createProject(FreeStyleProject.class, "some project");
p.scheduleBuild2(0).get();
FreeStyleBuild build2 = p.scheduleBuild2(0).get();
p.scheduleBuild2(0).get();
String id = build2.getExternalizableId();
assertEquals("dir/sub dir/some project#2", id);
assertEquals(build2, Run.fromExternalizableId(id));
RunParameterDefinition def = new RunParameterDefinition("build", "dir/sub dir/some project", "my build");
assertEquals("dir/sub dir/some project", def.getProjectName());
assertEquals(p, def.getProject());
EnvVars env = new EnvVars();
def.getDefaultParameterValue().buildEnvVars(null, env);
assertEquals(j.jenkins.getRootUrl() + "job/dir/job/sub%20dir/job/some%20project/3/", env.get("build"));
RunParameterValue val = def.createValue(id);
assertEquals(build2, val.getRun());
assertEquals("dir/sub dir/some project", val.getJobName());
assertEquals("2", val.getNumber());
val.buildEnvVars(null, env);
assertEquals(j.jenkins.getRootUrl() + "job/dir/job/sub%20dir/job/some%20project/2/", env.get("build"));
assertEquals("dir/sub dir/some project", env.get("build.jobName"));
assertEquals("2", env.get("build.number"));
}

}

0 comments on commit de9002b

Please sign in to comment.