小编典典

Jenkins:使用Groovy配置AD插件授权

jenkins

我正在通过Groovy配置Active
Directory。我能够通过UI通过活动目录进行身份验证,这意味着端口和身份验证不是问题。我有以下基于LDAP插件的内容:

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

String domain = 'my.domain.com'
String site = ''
String server = '192.168.1.1'
String bindName = 'account@my.domain.com'
String bindPassword = 'password'

SecurityRealm ad_realm = new ActiveDirectorySecurityRealm(domain, site, bindName, bindPassword, server)
jenkins.instance.setSecurityRealm(ad_realm)

这是错误:

ERROR: jenkins_script[add_active_directory] (jenkins_wrapper::ldap line 32) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '255'
   ---- Begin output of "/opt/java/latest/bin/java" -jar "/tmp/kitchen/cache/jenkins-cli.jar" -s http://localhost:8080 groovy /tmp/groovy20160208-28479-azdr83 ----
   STDOUT: 
   STDERR: groovy.lang.MissingPropertyException: No such property: jenkins for class: RemoteClass
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
    at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
    at RemoteClass.run(RemoteClass:16)
    at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:266)
    at groovy.lang.GroovyShell.run(GroovyShell.java:517)
    at hudson.cli.GroovyCommand.run(GroovyCommand.java:86)
    at hudson.cli.CLICommand.main(CLICommand.java:237)
    at hudson.cli.CliManagerImpl.main(CliManagerImpl.java:92)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:608)
    at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:583)
    at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:542)
    at hudson.remoting.UserRequest.perform(UserRequest.java:120)
    at hudson.remoting.UserRequest.perform(UserRequest.java:48)
    at hudson.remoting.Request$2.run(Request.java:326)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
    at hudson.cli.CliManagerImpl$1.call(CliManagerImpl.java:63)
    at hudson.remoting.CallableDecoratorAdapter.call(CallableDecoratorAdapter.java:18)
   atorList.java:21)
    at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

对这个错误有任何见解吗?

更新

新密码

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

    def instance = Jenkins.getInstance()
    String domain = 'my.domain.com'
    String site = ''
    String server = '1.2.3.4'
    String bindName = 'bind@my.domain.com'
    String bindPassword = '#{bind_password}'
    adrealm = ActiveDirectorySecurityRealm(domain, site, bindName, bindPassword, server)
    instance.setSecurityRealm(adrealm)

新错误

STDERR: groovy.lang.MissingMethodException: No signature of method: RemoteClass.ActiveDirectorySecurityRealm() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) values: [my.domain.com, , account@my.domain.com, ...]
            at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
            at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:78)
            at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
            at RemoteClass.run(RemoteClass:15)
            at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:266)
            at groovy.lang.GroovyShell.run(GroovyShell.java:517)
            at hudson.cli.GroovyCommand.run(GroovyCommand.java:86)
            at hudson.cli.CLICommand.main(CLICommand.java:237)
            at hudson.cli.CliManagerImpl.main(CliManagerImpl.java:92)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:497)
            at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:608)
            at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:583)
            at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:542)
            at hudson.remoting.UserRequest.perform(UserRequest.java:120)
            at hudson.remoting.UserRequest.perform(UserRequest.java:48)
            at hudson.remoting.Request$2.run(Request.java:326)
            at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
            at hudson.cli.CliManagerImpl$1.call(CliManagerImpl.java:63)
            at hudson.remoting.CallableDecoratorAdapter.call(CallableDecoratorAdapter.java:18)
            at hudson.remoting.CallableDecoratorList$1.call(CallableDecoratorList.java:21)
            at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
            at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:745)

阅读 361

收藏
2020-07-25

共1个答案

小编典典

因此,有了建议中的所有新增功能,

尝试:

adrealm =新的ActiveDirectorySecurityRealm(域,站点,bindName,bindPassword,服务器)

2020-07-25