CredentialsProvider: extend public API with find*() and get*() method variants that can specify the Run - #1071
Open
jimklimov wants to merge 4 commits into
Open
CredentialsProvider: extend public API with find*() and get*() method variants that can specify the Run#1071jimklimov wants to merge 4 commits into
jimklimov wants to merge 4 commits into
Conversation
… variants that can specify the Run Until now the `build` passed into some methods was used to get its "parent" (such as a Jenkins Folder) and use it as context for persistently configured credentials; the `build` was then effectively discarded during lookups in available credentials storages (not passed into methods that CredentialsProvider descendant classes can actually override). With this change, additional method signatures are added which allow the `Run` argument to be passed further down the road, so credential stores scoped to individual builds (such as with the "Ephemeral Credentials" plugin) can reliably know which code path they were called for during a lookup. Default implementations short-circuit to old code without the `run` argument, so existing plugins should not notice the change until they decide to `@Override` the new methods. Signed-off-by: Jim Klimov <jimklimov+jenkinsci@gmail.com> Co-authored-by: Claude Sonnet 4.6
…edential store search for narrowest scoping Signed-off-by: Jim Klimov <jimklimov+jenkinsci@gmail.com> Co-authored-by: Claude Sonnet 4.6
…errides should be preferred over use of `run` argument Signed-off-by: Jim Klimov <jimklimov+jenkinsci@gmail.com> Co-authored-by: Claude Sonnet 4.6
This was referenced Jul 30, 2026
Contributor
Author
|
Consuming PR changed to jenkinsci/ephemeral-credentials-plugin#2 now that the new plugin is hosted. |
jimklimov
added a commit
to jenkinsci/ephemeral-credentials-plugin
that referenced
this pull request
Aug 5, 2026
…ds in credentials-plugin - new getCredentialsInItemGroup() signature with a `Run` Requires jenkinsci/credentials-plugin#1071 Signed-off-by: Evgeny Klimov <klimov@provys.com>
jimklimov
added a commit
to jenkinsci/ephemeral-credentials-plugin
that referenced
this pull request
Aug 6, 2026
…ds in credentials-plugin - new getCredentialsInItemGroup() signature with a `Run` Requires jenkinsci/credentials-plugin#1071 Signed-off-by: Evgeny Klimov <klimov@provys.com>
jimklimov
added a commit
to jenkinsci/ephemeral-credentials-plugin
that referenced
this pull request
Aug 6, 2026
…ds in credentials-plugin - new getCredentialsInItemGroup() signature with a `Run` Requires jenkinsci/credentials-plugin#1071 Signed-off-by: Evgeny Klimov <klimov@provys.com>
jimklimov
added a commit
to jenkinsci/ephemeral-credentials-plugin
that referenced
this pull request
Aug 7, 2026
…ds in credentials-plugin - new getCredentialsInItemGroup() signature with a `Run` Requires jenkinsci/credentials-plugin#1071 Signed-off-by: Evgeny Klimov <klimov@provys.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Until now the
buildorrunreference passed into some methods was used to get its "parent" (such as a Jenkins Folder) and use it as context for persistently configured credentials; thebuildwas then effectively discarded during lookups in available credentials stores (not passed into methods thatCredentialsProviderdescendant classes can actually override).With this change, additional method signatures are added which allow the
Runargument to be passed further down the road, so credential stores scoped to individual builds (such as with the "Ephemeral Credentials" plugin, hosting pending per jenkins-infra/repository-permissions-updater#5182) can reliably know which code path they were called for during a lookup done bywithCredentials,checkout,sshagentand other plugin steps or Java code.The common entry path for code which wants to find some relevant credentials is to call
static CredentialsProvider findCredentialById(id, type, run, criteria)which internally calledfindCredentialByIdInItem()-- originally the variant which did not accept therunobject as its argument, and newly the variant which does.Default implementations short-circuit to old code without the
runargument, so existing plugins should not notice the change until they decide to@Overridethe new methods.Testing done
Experimenting how it goes with work on "Ephemeral Credentials" plugin, currently in a side branch - see https://github.com/jimklimov/ephemeral-credentials/pull/1 - HPI files from a build of that PR and a build of this PR are deployed on an internal testing instance, seems satisfactory (log details posted to that PR).
Changes posted here did not preclude passing of existing credentials-plugin tests, at least locally.
Additional
src/test/java/com/cloudbees/plugins/credentials/RunAwareLookupTest.javacrafted specifically for passingRunarguments.For a bit more context: The problem was actually found during work on that "Ephemeral Credentials" plugin: it seemed "obvious" that when we get called from a pipeline or other build, we can know who the caller is, and look up exactly the credentials stored by that build, not by its siblings (same job, different number) or neighbors in a job folder. It turned out that this information is not available in all contexts (e.g. easy to see directly in a pipeline step like
withEphemeralCredentialsoffered by that plugin, but not when somecheckoutsimply iterates all credential stores to see if somebody defines what it asks for). Experiments with discovery of a thread or executor, or looking at call stack traces, proved outright dysfunctional, or unreliable, or too expensive - and in any case they are hacks that would likely be broken sooner or later by evolution of Jenkins and/or Java. So the best solution is to directly hand down the relevant information this plugin already has, just chose to forget until now.Submitter checklist