Skip to content
Permalink
Browse files

[FIXED JENKINS-9686] Expand default values of string parameters when …

…polling.
  • Loading branch information...
jglick committed May 8, 2013
1 parent c9a881d commit 7d5b7d52221b55e7cb6bee5ae280bb3ecd2ffe9f
@@ -151,6 +151,25 @@ public String getBranch() {
return branch == null ? "default" : branch;
}

/**
* Same as {@link #getBranch()} but with <em>default</em> values of parameters expanded.
*/
private String getBranchExpanded(AbstractProject<?,?> project) {
EnvVars env = new EnvVars();
ParametersDefinitionProperty params = project.getProperty(ParametersDefinitionProperty.class);
if (params != null) {
for (ParameterDefinition param : params.getParameterDefinitions()) {
if (param instanceof StringParameterDefinition) {
String dflt = ((StringParameterDefinition) param).getDefaultValue();
if (dflt != null) {
env.put(param.getName(), dflt);
}
}
}
}
return getBranch(env);
}

private String getBranch(EnvVars env) {
return branch == null ? "default" : env.expand(branch);
}
@@ -242,7 +261,7 @@ protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project,
throw new IOException("Could not use cache to poll for changes. See error messages above for more details");
}
FilePath repositoryCache = new FilePath(new File(possiblyCachedRepo.getRepoLocation()));
return compare(launcher, listener, baseline, output, Hudson.getInstance(), repositoryCache);
return compare(launcher, listener, baseline, output, Hudson.getInstance(), repositoryCache, project);
}
// XXX do canUpdate check similar to in checkout, and possibly return INCOMPARABLE

@@ -251,9 +270,9 @@ protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project,
Node node = project.getLastBuiltOn(); // JENKINS-5984: ugly but matches what AbstractProject.poll uses; though compare JENKINS-14247
FilePath repository = workspace2Repo(workspace);

pull(launcher, repository, listener, output, node,getBranch());
pull(launcher, repository, listener, output, node, getBranchExpanded(project));

return compare(launcher, listener, baseline, output, node, repository);
return compare(launcher, listener, baseline, output, node, repository, project);
} catch(IOException e) {
if (causedByMissingHg(e)) {
listener.error(Messages.MercurialSCM_failed_to_compare_with_remote_repository());
@@ -265,10 +284,11 @@ protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project,
}
}

private PollingResult compare(Launcher launcher, TaskListener listener, MercurialTagAction baseline, PrintStream output, Node node, FilePath repository) throws IOException, InterruptedException {
private PollingResult compare(Launcher launcher, TaskListener listener, MercurialTagAction baseline, PrintStream output, Node node, FilePath repository, AbstractProject<?,?> project) throws IOException, InterruptedException {
HgExe hg = new HgExe(this, launcher, node, listener, /*XXX*/new EnvVars());
String remote = hg.tip(repository, getBranch());
String rev = hg.tipNumber(repository, getBranch());
String _branch = getBranchExpanded(project);
String remote = hg.tip(repository, _branch);
String rev = hg.tipNumber(repository, _branch);
if (remote == null) {
throw new IOException("failed to find ID of branch head");
}
@@ -8,7 +8,9 @@
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Result;
import hudson.model.StringParameterDefinition;
import hudson.model.StringParameterValue;
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;
@@ -302,6 +304,28 @@
new StringParameterValue("BRANCH", "b")));
}

@Bug(9686)
@Test public void pollingExpandsParameterDefaults() throws Exception {
m.hg(repo, "init");
m.touchAndCommit(repo, "trunk");
m.hg(repo, "update", "null");
m.hg(repo, "branch", "b");
m.touchAndCommit(repo, "variant");
FreeStyleProject p = j.createFreeStyleProject();
p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("branch", "default")));
p.setScm(new MercurialSCM(hgInstallation(), repo.getPath(), "${branch}", null, null, null, false));
String log = m.buildAndCheck(p, "trunk", new ParametersAction(new StringParameterValue("branch", "default")));
assertTrue(log, log.contains("--rev default"));
/* XXX cannot behave sensibly when workspace contains a branch build because the *current* trunk revision will be seen as new; would need to compare to all historical build records, or keep a separate workspace per branch:
log = m.buildAndCheck(p, "variant", new ParametersAction(new StringParameterValue("branch", "b")));
assertTrue(log, log.contains("--rev b"));
*/
assertEquals(PollingResult.Change.NONE, m.pollSCMChanges(p).change);
m.hg(repo, "update", "default");
m.touchAndCommit(repo, "trunk2");
assertEquals(PollingResult.Change.SIGNIFICANT, m.pollSCMChanges(p).change);
}

@Bug(6517)
@Test public void fileListOmittedForMerges() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();

0 comments on commit 7d5b7d5

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