How should you handle credentials in Jenkins?
⚡
Quick Answer
Store them in the Credentials store and inject with the credentials() helper or withCredentials block — never hard-code.
Detailed Answer
Jenkins encrypts credentials and exposes them to pipelines by ID, masking them in logs. environment { TOKEN = credentials('prod-token') } or withCredentials([...]) binds them to variables only for the needed steps. Scope credentials to folders/agents for least privilege.
Code Example
environment { AWS = credentials('aws-key') }💡
Interview Tip
Emphasize masking and least-privilege scoping.
jenkinscredentialssecrets