Use this when using credentials in Jenkins pipelines.
Credentials · Jenkins
Jenkins credentials store passwords, SSH keys, tokens and certificates encrypted on the controller, used in pipelines with withCredentials or credentials() so they are masked in logs.
1. Jenkins credentials store secrets.
2. Scope per folder/team.
3. Mask in logs.
4. External secret managers via plugins.
5. Rotate.
credential ID → withCredentials → masked env
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as controller/agent drift, plugin behavior changes, workspace contamination, credential leakage, retrying non-idempotent stages and green Pipeline status masking bad external state, choosing the cases most relevant to credential type/scope/ID, secure binding, masking, rotation and preventing credentials from leaking into logs/workspaces/artifacts.
Step 2 Common mistakes Narrow the fault
- Credentials echoed in logs.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Credentials are stored encrypted on the controller.
- withCredentials binds them and masks output.
- Scope credentials to folders where possible.
- Credentials store (scoped folder credentials) — storage
- withCredentials usage — injection
- Credential audit/rotation — hygiene
ReferenceWhy it matters1 section · depth on demand
In depth
Jenkins credentials store secrets — passwords, SSH keys, tokens, certificates — encrypted on the controller and expose them to builds only when a pipeline asks for them. Pipelines reference credentials by ID, so secrets never appear in Jenkinsfiles or job configuration.
withCredentials([
usernamePassword(credentialsId: 'netbox-api', usernameVariable: 'NB_USER', passwordVariable: 'NB_TOKEN'),
sshUserPrivateKey(credentialsId: 'ansible-ssh', keyFileVariable: 'SSH_KEY')
]) {
sh 'ansible-playbook -i inventory --private-key "$SSH_KEY" site.yml'
}
Jenkins masks known secret values in logs, but transformed values (base64, substrings) are not masked. Scope credentials to folders so only the jobs that need them can use them, and prefer short-lived tokens or an external secret store (HashiCorp Vault plugin) for high-value secrets.
ReferenceImportant terms & boundaries1 section · depth on demand
Mechanics
The linked authority for bounded mechanics is Jenkins Handbook — Using credentials; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Jenkins > Credentials. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.jenkins.io/doc/book/using/using-credentials/ · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For credential type/scope/ID, secure binding, masking, rotation and preventing credentials from leaking into logs/workspaces/artifacts, prefer typed fields and stable IDs over human presentation text.