Skip to content

Commit

Permalink
[FIXED JENKINS-19693]
Browse files Browse the repository at this point in the history
  • Loading branch information
almorelle committed Jan 14, 2014
1 parent 9b0e820 commit f0a01c8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 17 deletions.
Expand Up @@ -60,14 +60,29 @@ public Run<?,?> getBuild(Job<?,?> job, EnvVars env, BuildFilter filter, Run<?,?>
return null;
}

Run<?,?> run;
PermalinkProjectAction.Permalink p = job.getPermalinks().get(num);
if (p!=null) {
run = p.resolve(job);
return (run != null && filter.isSelectable(run, env)) ? run : null;
Run<?,?> run = null;

if(num.matches("[0-9]*")) {
//If its a number, retrieve the build.
run = job.getBuildByNumber(Integer.parseInt(num));
} else {
//Otherwise, check if the buildNumber value is a permalink or a display name.
PermalinkProjectAction.Permalink p = job.getPermalinks().get(num);
if (p == null) {
//Not a permalink so check if the buildNumber value is a display name.
for(Run<?,?> build: job.getBuilds()){
if(num.equals(build.getDisplayName())) {
//First named build found is the right one, going from latest build to oldest.
run = build;
break;
}
}
} else {
//Retrieve the permalink
run = p.resolve(job);
}
}

run = job.getBuildByNumber(Integer.parseInt(num));
if (run == null) {
LOGGER.log(Level.FINE, "no such build {0} in {1}", new Object[] {num, job.getFullName()});
return null;
Expand Down
Expand Up @@ -23,16 +23,7 @@ THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form">
<f:entry title="${%Build number}">
<f:textbox clazz="required pos-num-or-param" name="buildNumber"
value="${selector.buildNumber}"/>
<st:once>
<script type="text/javascript"><![CDATA[ Behaviour.register({
"INPUT.pos-num-or-param": function(e) {
registerRegexpValidator(e,/^(\d*[1-9]\d*|\$$\w+|)$$/,
'${h.jsStringEscape('%Not a positive number or build parameter')}');
}});
]]></script>
</st:once>
<f:entry title="${%Build number}" help="/plugin/copyartifact/help-specificBuild.html">
<f:textbox name="buildNumber" value="${selector.buildNumber}"/>
</f:entry>
</j:jelly>
6 changes: 6 additions & 0 deletions src/main/webapp/help-specificBuild.html
@@ -0,0 +1,6 @@
<div>
While this selector is for build numbers (e.g. "22" for build #22),
you can also resolve build parameters or environment variables (e.g. "${PARAM}").
The display name of a build and permalinks (e.g. "lastSuccessfulBuild", "lastBuild"...)
can be used as well.
</div>
Expand Up @@ -20,4 +20,34 @@ public void testUnsetVar() throws Exception {
assertEquals(null, s.getBuild(p, new EnvVars("HUM", "two"), f, null));
}

@Bug(19693)
public void testDisplayName() throws Exception {
FreeStyleProject p = createFreeStyleProject();
assertBuildStatusSuccess(p.scheduleBuild2(0));
assertBuildStatusSuccess(p.scheduleBuild2(0));
assertBuildStatusSuccess(p.scheduleBuild2(0));
assertEquals(3, p.getLastBuild().number);
p.getBuildByNumber(2).setDisplayName("RC1");
BuildSelector s = new SpecificBuildSelector("$NUM");
BuildFilter f = new BuildFilter();
assertEquals(p.getBuildByNumber(2), s.getBuild(p, new EnvVars("NUM", "RC1"), f, null));
assertEquals(null, s.getBuild(p, new EnvVars("NUM", "RC2"), f, null));
}

public void testPermalink() throws Exception {
FreeStyleProject p = createFreeStyleProject();
assertBuildStatusSuccess(p.scheduleBuild2(0));
assertBuildStatusSuccess(p.scheduleBuild2(0));
assertBuildStatusSuccess(p.scheduleBuild2(0));
assertEquals(3, p.getLastBuild().number);
BuildSelector s = new SpecificBuildSelector("$NUM");
BuildFilter f = new BuildFilter();
assertEquals(p.getLastSuccessfulBuild(), s.getBuild(p, new EnvVars("NUM", "lastSuccessfulBuild"), f, null));
assertEquals(p.getLastStableBuild(), s.getBuild(p, new EnvVars("NUM", "lastStableBuild"), f, null));
assertEquals(p.getLastBuild(), s.getBuild(p, new EnvVars("NUM", "lastBuild"), f, null));
assertEquals(p.getLastFailedBuild(), s.getBuild(p, new EnvVars("NUM", "lastFailedBuild"), f, null));
assertEquals(p.getLastUnstableBuild(), s.getBuild(p, new EnvVars("NUM", "lastUnstableBuild"), f, null));
assertEquals(p.getLastUnsuccessfulBuild(), s.getBuild(p, new EnvVars("NUM", "lastUnsuccessfulBuild"), f, null));
}

}

0 comments on commit f0a01c8

Please sign in to comment.