Skip to content

Instantly share code, notes, and snippets.

@actionjack
Forked from mllrjb/README.md
Created February 14, 2019 14:15
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 actionjack/f6b32545ea099006785a616c828c1d91 to your computer and use it in GitHub Desktop.
Save actionjack/f6b32545ea099006785a616c828c1d91 to your computer and use it in GitHub Desktop.
Jenkins init.groovy.d LDAP Authentication

Usage

Set LDAP_BIND_USER and LDAP_BIND_PASSWORD environment variables in the system (e.g. when creating your Docker container, etc).

import jenkins.model.*
import hudson.security.*
import org.jenkinsci.plugins.*
String server = 'ldaps://ldap.mllrjb.com:636'
String rootDN = 'o=mllrjb.com'
String userSearchBase = ''
String userSearch = 'uid={0}'
String groupSearchBase = 'ou=Groups'
String bindDn = env.LDAP_BIND_USER;
String bindPassword = env.LDAP_BIND_PASSWORD;
boolean inhibitInferRootDN = false
SecurityRealm ldap_realm = new LDAPSecurityRealm(server, rootDN, userSearchBase, userSearch, groupSearchBase, bindDn, bindPassword, inhibitInferRootDN)
Jenkins.instance.setSecurityRealm(ldap_realm)
Jenkins.instance.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment