0
0
JenkinsHow-ToBeginner · 3 min read

How to Add Credential in Jenkins: Step-by-Step Guide

To add a credential in Jenkins, go to Manage Jenkins > Manage Credentials, select the appropriate domain, then click Add Credentials. Fill in the credential details like type, ID, and secret, then save it for use in your Jenkins jobs or pipelines.
📐

Syntax

Adding credentials in Jenkins involves navigating through the Jenkins UI and filling out a form with specific fields:

  • Scope: Defines where the credential can be used (Global or System).
  • Kind: Type of credential (e.g., Username with password, Secret text, SSH key).
  • ID: Optional unique identifier for referencing the credential.
  • Description: A helpful note to identify the credential.
  • Secret or Username/Password: The actual sensitive data to store.
jenkins
Manage Jenkins > Manage Credentials > (select domain) > Add Credentials

Fields:
- Scope: Global or System
- Kind: Username with password, Secret text, SSH Username with private key, etc.
- ID: Optional unique ID
- Description: Text description
- Secret/Username/Password: Credential data
💻

Example

This example shows how to add a Username with password credential in Jenkins:

jenkins
1. Open Jenkins dashboard.
2. Click <strong>Manage Jenkins</strong>.
3. Click <strong>Manage Credentials</strong>.
4. Select a domain (e.g., <code>(global)</code>).
5. Click <strong>Add Credentials</strong> on the left.
6. Choose <strong>Kind</strong> as <code>Username with password</code>.
7. Enter your username and password.
8. Optionally set an ID and description.
9. Click <strong>OK</strong> to save.
Output
Credential saved successfully and available for Jenkins jobs.
⚠️

Common Pitfalls

  • Not selecting the correct domain can make credentials unavailable to jobs.
  • Leaving the ID blank can cause confusion when referencing credentials in pipelines.
  • Using System scope unnecessarily can expose credentials to more jobs than needed.
  • Forgetting to save after adding credentials will lose your input.
jenkins
Wrong way:
- Adding credential in wrong domain or scope
- Leaving ID empty and forgetting description

Right way:
- Choose correct domain (usually <code>(global)</code>)
- Set meaningful ID and description
- Use <code>Global</code> scope unless restricted access is needed
📊

Quick Reference

FieldDescriptionExample
ScopeDefines where credential is usableGlobal
KindType of credentialUsername with password
IDUnique identifier for referencingmy-cred-id
DescriptionNotes about the credentialGitHub access token
Secret/Username/PasswordSensitive data storedusername + password

Key Takeaways

Add credentials via Manage Jenkins > Manage Credentials for secure storage.
Choose the correct domain and scope to control credential access.
Use meaningful IDs and descriptions for easy reference in pipelines.
Always save credentials after adding to avoid losing data.
Avoid using System scope unless necessary to limit exposure.