From 79609cd051da15151d7563e186676ae4dce35178 Mon Sep 17 00:00:00 2001 From: Jeremy Bouse Date: Thu, 16 Aug 2018 12:54:02 -0400 Subject: [PATCH] Re-order check to create admin user * If we can't create the user don't attempt to iterate over current users to see if admin user exists --- master/init.groovy.d/configure-jenkins-admin.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/master/init.groovy.d/configure-jenkins-admin.groovy b/master/init.groovy.d/configure-jenkins-admin.groovy index bd3cfa1..b5a36b3 100644 --- a/master/init.groovy.d/configure-jenkins-admin.groovy +++ b/master/init.groovy.d/configure-jenkins-admin.groovy @@ -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