Build aborts at withCredentials when duplicate credential IDs span system and folder stores
0 reputation · 07 Aug 2021, 04:19 UTC
0 reputation · 07 Aug 2021, 04:19 UTC
A Jenkins Pipeline using withCredentials fails the build when a referenced credential ID cannot be resolved by any provider. The unresolved behavior concerns duplicate IDs: the same identifier can exist in the system store, a folder store, and a user store. In that situation, the binding step completes rather than aborting, but the value actually injected depends on the run's item context and provider ordering.
Testing an integration without production secrets typically involves placeholder credentials in a test folder. That validates Jenkins resolution and binding, but not the remote service. A passing test in one folder context can fail after the job is moved or copied because folder-scoped credentials only resolve when the job runs in that folder.
Because the Credentials plugin is a provider API with separate type plugins, the set of bindable types and lookup semantics changed across releases. A controller with pinned plugin versions may resolve duplicates differently than another controller.
What deterministic rules govern which store wins when the same credential ID is present in the system, folder, and user stores for a given Pipeline run? Does the resolution order differ between freestyle and Pipeline jobs, or between root-level and folder-scoped items? Which plugin versions introduced changes to this lookup order that would require re-testing existing credential configurations?
35275 reputation · 07 Aug 2021, 13:05 UTC
The deterministic resolution order for a Pipeline or freestyle run is: folder-scoped credentials (if the item lives in a folder that defines a credentials store) → system (global) credentials → user-scoped credentials. The first provider that returns a non-null Credentials instance for the requested ID wins. This order is identical for freestyle build wrappers and Pipeline withCredentials steps because both use the same CredentialsProvider.lookupCredentials() API when the run executes in the same item context.
| Plugin | Version | Date | Change |
|---|---|---|---|
| CloudBees Folders | 5.0 | 2016 | Introduced folder-scoped credential stores |
| Credentials | 2.0 | 2016 | Reworked provider SPI; kept folder→system→user precedence |
| Credentials | 2.3.0 | 2018 | Added UserCredentialsProvider, placing user store last |
No later release has changed this order. If your controller pins Credentials plugin < 2.3.0, user-scoped credentials may not participate at all. Re-test after upgrading past these versions.
CredentialsProvider implementations (HashiCorp Vault, CyberArk, proprietary plugins) can insert themselves at arbitrary priority via @Extension ordering, potentially changing the effective precedence.withCredentials([string(credentialsId: 'DUP_ID', variable: 'SEC')]) {\n echo \"bound: ${env.SEC}\"\n}Run it from the folder and from root; observe which value is injected.FINE logging for com.cloudbees.plugins.credentials and com.cloudbees.hudson.plugins.folder during a run to see the exact provider lookup sequence.Do you have any third-party credential provider plugins installed (Vault, CyberArk, AWS Secrets Manager, etc.)? If yes, their @Extension ordering can override the standard folder→system→user precedence, and the recommendation shifts to auditing those providers' priority.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.