简体   繁体   中英

Setting “Domain controller” of the active-directory plugin in jenkins via groovy script

I am configuring the active-directory plugin in jenkins via groovy like this:

import jenkins.model.*
import hudson.security.*
import hudson.plugins.active_directory.*

def instance = Jenkins.getInstance()
String domain = "MY-DOMAIN.DE"
String site = ""
String server = "my-server:3268"
String bindName = ""
String bindPassword = ""
adrealm = new ActiveDirectorySecurityRealm(domain, site, bindName, bindPassword, server, GroupLookupStrategy.RECURSIVE)
instance.setSecurityRealm(adrealm)

It works. But the "Domain controller" is not set.

在此处输入图片说明

I was hoping, that the "server" would set it, but no. How can I set this via groovy script?

Backward compatibility of the constructor is failing, please use latest constructor (more here https://issues.jenkins-ci.org/browse/JENKINS-39676 ):

 @DataBoundConstructor
    // as Java signature, this binding doesn't make sense, so please don't use this constructor
    public ActiveDirectorySecurityRealm(String domain, List<ActiveDirectoryDomain> domains, String site, String bindName,
                                        String bindPassword, String server, GroupLookupStrategy groupLookupStrategy, boolean removeIrrelevantGroups, Boolean customDomain, CacheConfiguration cache) {

And the example:

import hudson.plugins.active_directory.* 
import jenkins.model.*

def instance = Jenkins.getInstance();
def ActiveDirectoryDomain adDomain = new ActiveDirectoryDomain("Example_Domain_Name_2", "Example_Domain_Controller_2");
def domains = new ArrayList<ActiveDirectoryDomain>();
domains.add(adDomain);

def securityRealm = new ActiveDirectorySecurityRealm( 
"", 
domains,
"", 
"",
"",  
"", 
GroupLookupStrategy.RECURSIVE,
false,
true,
null)
println(securityRealm.domains)

instance.setSecurityRealm(securityRealm) 
instance.save()

Works for me!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM