Created
April 23, 2020 12:09
-
-
Save marcelaraujo/5bd799be54ecb14b9dc3fb1d1473841d to your computer and use it in GitHub Desktop.
Update all users passwords
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hudson.model.User | |
import jenkins.model.Jenkins | |
import hudson.security.HudsonPrivateSecurityRealm | |
import hudson.security.HudsonPrivateSecurityRealm.Details | |
def instance = Jenkins.getInstance() | |
def realm = instance.getSecurityRealm() | |
def users = realm.getAllUsers() | |
def generator = { int n -> | |
def alphabet = ['a'..'z','A'..'Z',0..9,'_','!','@','#','$'].flatten() | |
new Random().with { | |
(1..n).collect { alphabet[ nextInt( alphabet.size() ) ] }.join() | |
} | |
} | |
for (User u : users) { | |
def password = generator(12) | |
u.addProperty( Details.fromPlainPassword(password) ) | |
println "${u.getId()},${u.getProperty(Mailer.UserProperty.class).getAddress()},${password}" | |
u.save() | |
} | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment