Skip to content

Conversation

@jglick
Copy link
Member

@jglick jglick commented Sep 11, 2025

Fixes jenkinsci/ec2-fleet-plugin#491 and similarly enables jenkinsci/jenkins#11055.

Using utility from #62 (comment) rather than copying StaplerReferer from other plugins, where it is limited to Item (here we actually need User at least). See also #373 (comment).

…than directly `StaplerRequest2.findAncestorObject`
if (request != null) {
context = request.findAncestorObject(ModelObject.class);
}
context = CredentialsDescriptor.findContextInPath(ModelObject.class);
Copy link
Member

@jtnord jtnord Sep 11, 2025

Choose a reason for hiding this comment

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

The existing code had a check that we are in a Stapler request. if that was needed this will now throw a NullPointerException, did you check that calls to this are only web methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can double check but the other overload of this method passed in StaplerRequest2 already without checking. (It would make no sense outside of a request context.)

Copy link
Member Author

Choose a reason for hiding this comment

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

CredentialsSelectHelper methods touched here are used from

<j:set var="context" value="${selectHelper.resolveContext(attrs.context ?: it)}"/>
<j:set var="storeItems" value="${selectHelper.getStoreItems(context, includeUser)}"/>
<j:choose>
<j:when test="${selectHelper.hasCreatePermission(context, includeUser) and storeItems != null and !storeItems.isEmpty()}">

Whereas

public static <T extends ModelObject> T findContextInPath(@NonNull StaplerRequest2 request, @NonNull Class<T> type) {
is used from
return CredentialsDescriptor.findContextInPath(request, type);

Comment on lines -125 to -129
StaplerRequest2 request = Stapler.getCurrentRequest2();
if (request != null) {
return request.findAncestorObject(ModelObject.class);
}
return null;
Copy link
Member

Choose a reason for hiding this comment

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

The existing code had a check that we where in a Stapler request. if that was needed this will now throw a NullPointerException, did you check that calls to this are only web methods, or that null is never passed for any non web methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jglick jglick requested a review from jtnord September 11, 2025 22:50
@jtnord jtnord merged commit 4cbb539 into jenkinsci:master Sep 12, 2025
18 checks passed
@jglick jglick deleted the StaplerReferer-JENKINS-19413 branch September 12, 2025 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to add SSH credential from cloud configuration page

2 participants