How to Create User in Jenkins: Step-by-Step Guide
To create a user in Jenkins, go to
Manage Jenkins > Manage Users > Create User, then fill in the username, password, full name, and email. Alternatively, use a script with Jenkins CLI or Groovy to automate user creation.Syntax
Creating a user in Jenkins can be done via the web interface or scripting. The web interface requires filling out a form with these fields:
- Username: Unique ID for the user.
- Password: Secure password for login.
- Full name: User's display name.
- Email address: Contact email.
For scripting, Jenkins uses Groovy scripts or CLI commands to add users programmatically.
groovy
jenkins.model.Jenkins.instance.securityRealm.createAccount('username', 'password')
Example
This example shows how to create a user named newuser with password password123 using the Jenkins Script Console.
groovy
import jenkins.model.* import hudson.security.* def instance = Jenkins.getInstance() def hudsonRealm = instance.getSecurityRealm() hudsonRealm.createAccount('newuser', 'password123') instance.save()
Output
User 'newuser' created successfully.
Common Pitfalls
Common mistakes when creating users in Jenkins include:
- Trying to create a user without enabling Jenkins' own user database (security realm).
- Using weak or empty passwords.
- Not saving the Jenkins instance after scripting user creation.
- Confusing user creation with authorization setup.
Always ensure the security realm is set to Jenkins' own user database before adding users.
groovy
/* Wrong: Trying to create user without Jenkins own user database enabled */ // This will fail if security realm is not Jenkins' own jenkins.model.Jenkins.instance.securityRealm.createAccount('user', 'pass') /* Right: Set security realm first */ import jenkins.model.* import hudson.security.* def instance = Jenkins.getInstance() instance.setSecurityRealm(new HudsonPrivateSecurityRealm(false)) instance.getSecurityRealm().createAccount('user', 'pass') instance.save()
Quick Reference
Summary tips for creating users in Jenkins:
- Use
Manage Jenkins > Manage Users > Create Userfor manual creation. - Use Groovy scripts in the Script Console for automation.
- Ensure Jenkins uses its own user database (HudsonPrivateSecurityRealm).
- Always save changes after scripting user creation.
- Set strong passwords for security.
Key Takeaways
Create users via Jenkins web UI under Manage Jenkins > Manage Users > Create User.
Use Groovy scripts in Jenkins Script Console for automated user creation.
Ensure Jenkins security realm is set to its own user database before adding users.
Always save Jenkins instance after scripting changes to persist users.
Use strong passwords and proper user management for security.