警告:我对EnterpriseLinux很好,但是假设我对Jenkins,jars,wars,jpis,java和groovy充其量是勉强的。很抱歉。
我已经在RHEL7上设置了一个詹金斯盒子,主要是通过(必定是腐烂的)Chef Cookbook,所以它是可重复的并且几乎是白痴的。在添加模块时,我是通过本地文件(安全站点,没有网络访问权限)添加HPI,如下所示:
plugins=%w(active-directory mailer display-url-api)
require 'digest'
plugins
.each_with_index do |plugin_with_version, index|
p, v = plugin_with_version.split(':') # yeah I know
source = "#{Chef::Config[:file_cache_path]}/cookbooks/#{cookbook_name}/files/default/#{p}.hpi"
directory "#{node['jenkins']['master']['home']}/plugins" do
owner node['jenkins']['master']['user']
group node['jenkins']['master']['group']
mode 0755
end
cookbook_file "#{node['jenkins']['master']['home']}/plugins/#{p}.hpi" do
action :create
owner node['jenkins']['master']['user']
group node['jenkins']['master']['group']
mode 0755
notifies :create, "ruby_block[jenkins_restart_flag]", :immediately
end
end
当我使用HPI预先处理文件部分时,它会填充/ var / lib / jenkins / plugins位置,所以我想到达了。
# ls -l /var/lib/jenkins/plugins/
total 708
drwxr-xr-x 6 jenkins jenkins 77 Aug 30 08:37 active-directory
-rwxr-xr-x 1 jenkins jenkins 583280 Aug 30 08:37 active-directory.hpi
drwxr-xr-x 4 jenkins jenkins 53 Aug 30 08:37 display-url-api
-rwxr-xr-x 1 jenkins jenkins 19478 Aug 30 08:37 display-url-api.hpi
drwxr-xr-x 4 jenkins jenkins 53 Aug 30 08:37 mailer
-rwxr-xr-x 1 jenkins jenkins 115745 Aug 30 08:37 mailer.hpi
实际上,所有三个插件似乎都在/ pluginManager / installed中处于活动状态:
active directory plugin 2.8
Display URL API 2.2.0
Mailer Plugin 1.21
..和两个部门将其复选框选中并显示为灰色,其中仅检查了AD插件。那表明它们已经安装并激活了,但是我猜是这样。
我认为,现在可以配置AD插件了,这就是今天发生严重错误的地方。
Here是我正在使用的脚本,about the 5th such script(当Google大脑的线索):
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()
但是调用完全失败了。错误消息的内容,消除了厨师的麻烦,是:
---- Begin output of "/usr/lib/jvm/java-1.8.0/bin/java" -jar "/var/chef/cache/jenkins-cli.jar" -s http://localhost:8080 -"remoting" groovy = ----
STDOUT:
STDERR: Aug 30, 2018 1:32:03 PM org.jenkinsci.remoting.util.AnonymousClassWarnings warn
WARNING: Attempt to (de-)serialize anonymous class hudson.cli.ClientAuthenticationCache$1; see: https://jenkins.io/redirect/serialization-of-anonymous-classes/
ERROR: Unexpected exception occurred while performing groovy command.
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: hudson.plugins.active_directory.ActiveDirectorySecurityRealm(java.lang.String, java.util.ArrayList, java.lang.String, java.lang.String, java.lang.String, java.lang.String, hudson.plugins.active_directory.GroupLookupStrategy, java.lang.Boolean, java.lang.Boolean, null)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1732)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1532)
at org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSite.java:49)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at RemoteClass.run(RemoteClass:9)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
at groovy.lang.GroovyShell.run(GroovyShell.java:518)
at groovy.lang.GroovyShell.run(GroovyShell.java:497)
at hudson.cli.GroovyCommand.run(GroovyCommand.java:89)
at hudson.cli.CLICommand.main(CLICommand.java:280)
at hudson.cli.CliManagerImpl.main(CliManagerImpl.java:95)
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:498)
at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:929)
at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:903)
at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:855)
at hudson.remoting.UserRequest.perform(UserRequest.java:212)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request$2.run(Request.java:369)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at hudson.cli.CliManagerImpl$1.call(CliManagerImpl.java:66)
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 jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:71)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
---- End output of "/usr/lib/jvm/java-1.8.0/bin/java" -jar "/var/chef/cache/jenkins-cli.jar" -s http://localhost:8080 -"remoting" groovy = ----
没有欢乐吧?这是最佳选择:
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: hudson.plugins.active_directory.ActiveDirectorySecurityRealm(java.lang.String, java.util.ArrayList, java.lang.String, java.lang.String, java.lang.String, java.lang.String, hudson.plugins.active_directory.GroupLookupStrategy, java.lang.Boolean, java.lang.Boolean, null)
现在,在我们深入探讨这一脚本之前,我想说的是,我也尝试过的其他脚本(实际上是3或4个),就像Internet van-candy一样,也具有类似的构造函数错误。我可以运行这些错误,并在需要时提供错误以进行比较,但是我想建议的是,它闻起来像是一个更大的问题,尽管看起来一切正常,但我的插件在某种程度上并没有放入应有的代码中。再次,仍在猜测。
是的,在其他3-4次尝试中,我使用内部自定义数据对脚本进行了调整。士气低落,我什至没有打扰。但是我保证我会与其余人一起使用有效数据,并且如果我们可以克服构造函数错误,则计划使用实数值。
和问题,按照非常特殊的顺序:
感谢您阅读本文,希望您的生活愉快。 ;-)
答案 0 :(得分:1)
因此,Jenkins中的所有Groovy脚本在实际Java对象上都是很薄的一层,因此要找到正确的构造函数,我们需要查看插件的代码:https://github.com/jenkinsci/active-directory-plugin/blob/1b082cbfb7d236d326c218c7b474fb51cb930080/src/main/java/hudson/plugins/active_directory/ActiveDirectorySecurityRealm.java#L224-L270
如果我们以第一个构造函数为例:
ActiveDirectorySecurityRealm(String domain, String site, String bindName, String bindPassword, String server)
所以您可以这样称呼:
def securityRealm = new ActiveDirectorySecurityRealm("Example_Domain_Name_2", null, null, null, "Example_Domain_Controller_2")
或者类似的东西。
答案 1 :(得分:0)
首先,请记住在添加插件后重新启动Jenkins!这似乎是一件大事。
按照诺亚的提示,这对我有用:
import hudson.plugins.active_directory.*
import jenkins.model.*
def instance = Jenkins.getInstance();
// public ActiveDirectorySecurityRealm(String domain, String site, String bindName, String bindPassword, String server)
def securityRealm = new ActiveDirectorySecurityRealm(
'myRealm',
'Default-First-Site-Name',
'bindaddr@myRealm,
'bindpassword_cleartext',
'ad_server1fqdn,ad_server2fqdn'
)
securityRealm.getDomains().each({
it.site = securityRealm.site
it.bindName = securityRealm.bindName
it.bindPassword = securityRealm.bindPassword
})
instance.setSecurityRealm(securityRealm)
instance.save()
请注意,我也在此处添加了Konstantinos的tweak。
..并且有效!我认为。没有警报。直到我了解缺少保护代码和清除片段的情况,它才不断刷新不需要的位,并且从不删除应删除的位,这就是-绝对是一种我们不希望在其中使用它的地方永久存在的模式自动化。因此,无论如何我都坚持复制配置,但是至少我有生成它的模型。仍然是美好的一天。
将来:
非常感谢Konstantinos和Noah在这里。我显然不建议您给予他们荣誉,但是我非常感谢。