Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
boolean kindTrusted = kind.isTrusted();
for (LibraryConfiguration cfg : kind.forJob(build.getParent(), libraryVersions)) {
String name = cfg.getName();
if (name == null) {
continue;
}

if (!cfg.isImplicit() && !libraryVersions.containsKey(name)) {
continue; // not using this one at all
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class LibraryConfiguration extends AbstractDescribableImpl<LibraryConfigu
* Library name.
* Should match {@link Library#value}, up to the first occurrence of {@code @}, if any.
*/
@CheckForNull
public String getName() {
return name;
}
Expand Down Expand Up @@ -173,6 +174,9 @@ public FormValidation doCheckName(@QueryParameter String name) {

@RequirePOST
public FormValidation doCheckDefaultVersion(@AncestorInPath Item context, @QueryParameter String defaultVersion, @QueryParameter boolean implicit, @QueryParameter boolean allowVersionOverride, @QueryParameter String name) {
if (name.isEmpty()) {
return FormValidation.error("You must enter a name.");
}
if (defaultVersion.isEmpty()) {
if (implicit) {
return FormValidation.error("If you load a library implicitly, you must specify a default version.");
Expand All @@ -184,7 +188,7 @@ public FormValidation doCheckDefaultVersion(@AncestorInPath Item context, @Query
} else {
for (LibraryResolver resolver : ExtensionList.lookup(LibraryResolver.class)) {
for (LibraryConfiguration config : resolver.fromConfiguration(Stapler.getCurrentRequest())) {
if (config.getName().equals(name)) {
if (name.equals(config.getName())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be reverted

return config.getRetriever().validateVersion(name, defaultVersion, context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ public static class Execution extends AbstractSynchronousNonBlockingStepExecutio
@Override protected LoadedClasses run() throws Exception {
String[] parsed = LibraryAdder.parse(step.identifier);
String name = parsed[0], version = parsed[1];
if (name == null) {
throw new AbortException("No library name provided");
}
boolean trusted = false;
Boolean changelog = step.getChangelog();
LibraryCachingConfiguration cachingConfiguration = null;
Expand All @@ -177,7 +180,7 @@ public static class Execution extends AbstractSynchronousNonBlockingStepExecutio
if (retriever == null) {
for (LibraryResolver resolver : ExtensionList.lookup(LibraryResolver.class)) {
for (LibraryConfiguration cfg : resolver.forJob(run.getParent(), Collections.singletonMap(name, version))) {
if (cfg.getName().equals(name)) {
if (name.equals(cfg.getName())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

retriever = cfg.getRetriever();
trusted = resolver.isTrusted();
version = cfg.defaultedVersion(version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:entry field="identifier" title="${%Name and optional version}">
<f:textbox/>
<f:textbox clazz="required"/>
</f:entry>
<f:entry field="changelog" title="${%Include recent changes in jobs}">
<f:checkbox default="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,19 @@ public class LibraryStepTest {
r.assertLogContains("/lib/java", b);
r.assertLogContains("/pipeline/java", b);
}

@Issue("JENKINS-63355")
@Test public void emptyNameLibrariesAreSkipped() throws Exception {
sampleRepo.init();
sampleRepo.write("vars/x.groovy", "def call() {echo 'ran library'}");
sampleRepo.git("add", "vars");
sampleRepo.git("commit", "--message=init");
GlobalLibraries.get().setLibraries(List.of(
new LibraryConfiguration("stuff", new SCMSourceRetriever(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", true))),
new LibraryConfiguration("", new SCMSourceRetriever(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", true)))
));
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("library 'stuff@master'; x()", true));
WorkflowRun b = r.buildAndAssertSuccess(p);
}
}