From 16a8ba9a9711c52a0eb0d0f1668b8549e330bdc7 Mon Sep 17 00:00:00 2001 From: Craig Comstock Date: Tue, 26 Mar 2024 11:02:53 -0500 Subject: [PATCH] JENKINS-72643: Fixed listing regions when using ec2 instance profile credentials In the case where a user specified an ARN Role in the advanced section of cloud config we need to use that information when pulling the list of regions. In my case without this ARN Role being used with credentials I would get an empty drop-down list with no errors. I added a log message with the exception to expose a bit of information in case of failures. --- src/main/java/hudson/plugins/ec2/AmazonEC2Cloud.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/ec2/AmazonEC2Cloud.java b/src/main/java/hudson/plugins/ec2/AmazonEC2Cloud.java index 0441987a4..2b8ff0768 100644 --- a/src/main/java/hudson/plugins/ec2/AmazonEC2Cloud.java +++ b/src/main/java/hudson/plugins/ec2/AmazonEC2Cloud.java @@ -185,6 +185,9 @@ public FormValidation doCheckAltEC2Endpoint(@QueryParameter String value) { public ListBoxModel doFillRegionItems( @QueryParameter String altEC2Endpoint, @QueryParameter boolean useInstanceProfileForCredentials, + @QueryParameter String roleArn, + @QueryParameter String roleSessionName, + @QueryParameter String region, @QueryParameter String credentialsId) throws IOException, ServletException { @@ -192,7 +195,10 @@ public ListBoxModel doFillRegionItems( if (Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { try { AWSCredentialsProvider credentialsProvider = createCredentialsProvider(useInstanceProfileForCredentials, - credentialsId); + credentialsId, + roleArn, + roleSessionName, + region); AmazonEC2 client = AmazonEC2Factory.getInstance().connect(credentialsProvider, determineEC2EndpointURL(altEC2Endpoint)); DescribeRegionsResult regions = client.describeRegions(); List regionList = regions.getRegions(); @@ -201,6 +207,7 @@ public ListBoxModel doFillRegionItems( model.add(name, name); } } catch (SdkClientException ex) { + LOGGER.log(Level.INFO, "AmazonEC2Cloud.doFillRegionItems() got exception: " + ex); // Ignore, as this may happen before the credentials are specified } }