Skip to content

Instantly share code, notes, and snippets.

@marcelaraujo
Created April 23, 2020 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelaraujo/5bd799be54ecb14b9dc3fb1d1473841d to your computer and use it in GitHub Desktop.
Save marcelaraujo/5bd799be54ecb14b9dc3fb1d1473841d to your computer and use it in GitHub Desktop.
Update all users passwords
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