警告:我很擅长使用EnterpriseLinux,但我认为我对Jenkins,罐子,战争,jpis,java和groovy都不是最不情愿的行人。我很抱歉。
我在RHEL7上设置了一个Jenkins盒子,主要是通过(无可否认腐烂的)厨师食谱,所以它是可重复的,几乎是白痴。在添加模块时,我是通过本地文件(安全站点,无网络访问)添加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 /安装中处于活动状态:
active directory plugin 2.8
Display URL API 2.2.0
Mailer Plugin 1.21
..并且两个deps的盒子都经过检查和调暗,只是检查了AD插件。这表明它们已经安装并激活,但我猜。
现在我要配置AD插件,现在这里的情况非常糟糕。
Here是我正在使用的剧本,about the 5th such script(谷歌是我唯一的朋友,当大脑的离线线索时):
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个)脚本,比如互联网的糖果,也有类似的构造错误。如果需要的话,我可以运行那些并提供错误以进行比较,但我想建议的是它闻起来像一个更大的问题,不知何故我的插件不会丢失他们应该的代码,即使它看起来都没问题。再说一遍,还在猜测。
是的,在其他3-4次尝试中,我使用内部自定义数据调整了脚本;这个,士气如此之低,我甚至都没打扰。但我保证我使用其余的有效数据,如果我们可以通过构造函数错误,计划是使用实际值。
这些问题按照特定的顺序排列:
感谢您阅读这篇文章,我希望您的一天过得很顺利。 ;-)
因此,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")
或类似的东西。
首先,记得在添加插件后重启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也加入了这里。
..它工作了!我认为。没有警报。直到我理解缺少保护代码和清理部件使它不断刷新它不需要并且永远不会删除它应该的位,这是 - 绝对是一种模式,我们不喜欢延续我在哪里使用它自动化。所以我无论如何都要复制配置,但至少我有模型来生成它。仍然是美好的一天。
在将来:
非常感谢康斯坦丁诺斯和诺亚。我显然不能建议你给予他们信任,但我非常感激。