Skip to content

Commit

Permalink
Re-order check to create admin user
Browse files Browse the repository at this point in the history
* If we can't create the user don't attempt to iterate over current
users to see if admin user exists
  • Loading branch information
Jeremy Bouse committed Aug 16, 2018
1 parent fc7aa7a commit 79609cd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions master/init.groovy.d/configure-jenkins-admin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ if (j.getAuthorizationStrategy().getClass() == AuthorizationStrategy.Unsecured)

def adminUsername = System.getenv('JENKINS_ADMIN_USERNAME') ?: 'admin'
def adminPassword = System.getenv('JENKINS_ADMIN_PASSWORD') ?: 'password'
def currentUsers = j.getSecurityRealm().getAllUsers().collect { it.getId() }
if (!(adminUsername in currentUsers)) {
if (j.getSecurityRealm().metaClass.respondsTo(j.getSecurityRealm(), 'createAccount', String, String)) {
if (j.getSecurityRealm().metaClass.respondsTo(j.getSecurityRealm(), 'createAccount', String, String)) {
def currentUsers = j.getSecurityRealm().getAllUsers().collect { it.getId() }
if (!(adminUsername in currentUsers)) {
println("Created administrative user ${adminUsername}")
def user = j.getSecurityRealm().createAccount(adminUsername, adminPassword)
user.save
Expand Down

0 comments on commit 79609cd

Please sign in to comment.