Skip to content
Permalink
Browse files

[FIXED JENKINS-30357] Improved error handlings in ParameterizedBuildS…

…elector.
  • Loading branch information...
ikedam committed Sep 21, 2015
1 parent 6ddc88a commit 4e6cb78a2226ffe238a25ddfa788866c8cb4f131
@@ -59,8 +59,14 @@ public String getParameterName() {
LOG.log(Level.WARNING, "{0} is not defined", getParameterName());
return null;
}
return BuildSelectorParameter.getSelectorFromXml(xml)
.getBuild(job, env, filter, parent);
BuildSelector selector = null;
try {
selector = BuildSelectorParameter.getSelectorFromXml(xml);
} catch (Exception e) {
LOG.log(Level.SEVERE, String.format("Failed to resolve selector: %s", xml), e);
return null;
}
return selector.getBuild(job, env, filter, parent);
}

@Extension(ordinal=-20)
@@ -117,4 +117,95 @@ public void testWorkflow() throws Exception {
VirtualFile vf = b.getArtifactManager().root().child("artifact.txt");
assertEquals("foobar", IOUtils.toString(vf.open()));
}

/**
* Should not cause a fatal error even for a broken selector.
*
* @throws Exception
*/
@Test
public void testBrokenParameter() throws Exception {
FreeStyleProject copiee = j.createFreeStyleProject();
FreeStyleProject copier = j.createFreeStyleProject();

ParameterizedBuildSelector pbs = new ParameterizedBuildSelector("SELECTOR");
copier.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(
copiee.getFullName(),
null, // parameters
pbs,
"**/*", // filter
"", // excludes
false, // flatten
true, // optional
false // finterprintArtifacts
));
FreeStyleBuild b = (FreeStyleBuild) copier.scheduleBuild2(
0,
new ParametersAction(
new StringParameterValue("SELECTOR", "<SomeBrokenSelector")
)
).get();
j.assertBuildStatusSuccess(b);
}

/**
* Should not cause a fatal error even for an unavailable selector.
*
* @throws Exception
*/
@Test
public void testUnavailableSelector() throws Exception {
FreeStyleProject copiee = j.createFreeStyleProject();
FreeStyleProject copier = j.createFreeStyleProject();

ParameterizedBuildSelector pbs = new ParameterizedBuildSelector("SELECTOR");
copier.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(
copiee.getFullName(),
null, // parameters
pbs,
"**/*", // filter
"", // excludes
false, // flatten
true, // optional
false // finterprintArtifacts
));
FreeStyleBuild b = (FreeStyleBuild) copier.scheduleBuild2(
0,
new ParametersAction(
new StringParameterValue("SELECTOR", "<NoSuchSelector />")
)
).get();
j.assertBuildStatusSuccess(b);
}


/**
* Should not cause a fatal error even for an empty selector.
*
* @throws Exception
*/
@Test
public void testEmptySelector() throws Exception {
FreeStyleProject copiee = j.createFreeStyleProject();
FreeStyleProject copier = j.createFreeStyleProject();

ParameterizedBuildSelector pbs = new ParameterizedBuildSelector("SELECTOR");
copier.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(
copiee.getFullName(),
null, // parameters
pbs,
"**/*", // filter
"", // excludes
false, // flatten
true, // optional
false // finterprintArtifacts
));
FreeStyleBuild b = (FreeStyleBuild) copier.scheduleBuild2(
0,
new ParametersAction(
new StringParameterValue("SELECTOR", "")
)
).get();
j.assertBuildStatusSuccess(b);
}
}

0 comments on commit 4e6cb78

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