From 4167549fe1704bb415cfbb42c6639dc8510c96c9 Mon Sep 17 00:00:00 2001 From: Allan Burdajewicz Date: Thu, 25 Apr 2024 18:16:16 +1000 Subject: [PATCH 1/2] [JENKINS-72622] Rename CloudSet query parameter to avoid conflict --- core/src/main/java/jenkins/agents/CloudSet.java | 4 ++-- core/src/main/resources/jenkins/agents/CloudSet/_new.jelly | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/jenkins/agents/CloudSet.java b/core/src/main/java/jenkins/agents/CloudSet.java index e69a3f9add3c..8846487a1944 100644 --- a/core/src/main/java/jenkins/agents/CloudSet.java +++ b/core/src/main/java/jenkins/agents/CloudSet.java @@ -242,9 +242,9 @@ private void handleNewCloudPage(Descriptor descriptor, String name, Stapl */ @POST public synchronized void doDoCreate(StaplerRequest req, StaplerResponse rsp, - @QueryParameter String type) throws IOException, ServletException, Descriptor.FormException { + @QueryParameter String cloudDescriptorName) throws IOException, ServletException, Descriptor.FormException { Jenkins.get().checkPermission(Jenkins.ADMINISTER); - Cloud cloud = Cloud.all().find(type).newInstance(req, req.getSubmittedForm()); + Cloud cloud = Cloud.all().findByName(cloudDescriptorName).newInstance(req, req.getSubmittedForm()); if (!Jenkins.get().clouds.add(cloud)) { LOGGER.log(Level.WARNING, () -> "Creating duplicate cloud name " + cloud.name + ". Plugin " + Jenkins.get().getPluginManager().whichPlugin(cloud.getClass()) + " should be updated to support user provided name."); } diff --git a/core/src/main/resources/jenkins/agents/CloudSet/_new.jelly b/core/src/main/resources/jenkins/agents/CloudSet/_new.jelly index 3ea4d00d6acc..bc882a546e98 100644 --- a/core/src/main/resources/jenkins/agents/CloudSet/_new.jelly +++ b/core/src/main/resources/jenkins/agents/CloudSet/_new.jelly @@ -37,7 +37,7 @@ THE SOFTWARE. - + From 222df09444d4a9d819690dc714a103495e8c59fe Mon Sep 17 00:00:00 2001 From: Allan Burdajewicz Date: Wed, 15 May 2024 21:58:12 +1000 Subject: [PATCH 2/2] [JENKINS-72622] Address SpotBugs warning --- core/src/main/java/jenkins/agents/CloudSet.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/jenkins/agents/CloudSet.java b/core/src/main/java/jenkins/agents/CloudSet.java index 8846487a1944..addefceb83ff 100644 --- a/core/src/main/java/jenkins/agents/CloudSet.java +++ b/core/src/main/java/jenkins/agents/CloudSet.java @@ -244,7 +244,11 @@ private void handleNewCloudPage(Descriptor descriptor, String name, Stapl public synchronized void doDoCreate(StaplerRequest req, StaplerResponse rsp, @QueryParameter String cloudDescriptorName) throws IOException, ServletException, Descriptor.FormException { Jenkins.get().checkPermission(Jenkins.ADMINISTER); - Cloud cloud = Cloud.all().findByName(cloudDescriptorName).newInstance(req, req.getSubmittedForm()); + Descriptor cloudDescriptor = Cloud.all().findByName(cloudDescriptorName); + if (cloudDescriptor == null) { + throw new Failure(String.format("No cloud type ā€˜%sā€™ is known", cloudDescriptorName)); + } + Cloud cloud = cloudDescriptor.newInstance(req, req.getSubmittedForm()); if (!Jenkins.get().clouds.add(cloud)) { LOGGER.log(Level.WARNING, () -> "Creating duplicate cloud name " + cloud.name + ". Plugin " + Jenkins.get().getPluginManager().whichPlugin(cloud.getClass()) + " should be updated to support user provided name."); }