报错信息:

java.lang.RuntimeException: unsupported Java version: 11
at org.jruby.RubyInstanceConfig.initGlobalJavaVersion(RubyInstanceConfig.java:1674)
at org.jruby.RubyInstanceConfig.<clinit>(RubyInstanceConfig.java:1387)
Caused: java.lang.ExceptionInInitializerError
at org.jruby.embed.internal.AbstractLocalContextProvider.<init>(AbstractLocalContextProvider.java:42)
at org.jruby.embed.internal.SingleThreadLocalContextProvider.<init>(SingleThreadLocalContextProvider.java:43)
at org.jruby.embed.ScriptingContainer.getProviderInstance(ScriptingContainer.java:242)
at org.jruby.embed.ScriptingContainer.<init>(ScriptingContainer.java:226)
at org.jruby.embed.ScriptingContainer.<init>(ScriptingContainer.java:192)
at org.kohsuke.stapler.jelly.jruby.JRubyFacet.<init>(JRubyFacet.java:65)
at ruby.RubyRuntimePlugin.registerJRubyFacet(RubyRuntimePlugin.java:39)
at ruby.RubyRuntimePlugin.start(RubyRuntimePlugin.java:30)
at hudson.ClassicPluginStrategy.startPlugin(ClassicPluginStrategy.java:408)
at hudson.ClassicPluginStrategy.load(ClassicPluginStrategy.java:397)
Caused: java.io.IOException: Failed to initialize
at hudson.ClassicPluginStrategy.load(ClassicPluginStrategy.java:400)
at hudson.PluginManager.dynamicLoad(PluginManager.java:922)
Caused: java.io.IOException: Failed to install ruby-runtime plugin
at hudson.PluginManager.dynamicLoad(PluginManager.java:934)
at hudson.model.UpdateCenter$InstallationJob._run(UpdateCenter.java:2183)
Caused: java.io.IOException: Failed to dynamically deploy this plugin
at hudson.model.UpdateCenter$InstallationJob._run(UpdateCenter.java:2187)
at hudson.model.UpdateCenter$DownloadJob.run(UpdateCenter.java:1850)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at hudson.remoting.AtmostOneThreadExecutor$Worker.run(AtmostOneThreadExecutor.java:121)
at java.base/java.lang.Thread.run(Thread.java:829)

Jenkins容器安装ruby-runtime插件失败报错解决_2d

解决:

 从上面的报错信息分析可能是由于Jenkins容器中的Java 11版本过高。我们单独下载一个低版本的jdk,然后将低版本的jdk拷贝到Jenkins容器中替换掉之前的Java 11版本。

[root@k8s-master ~]# wget https://builds.openlogic.com/downloadJDK/openlogic-openjdk/8u262-b10/openlogic-openjdk-8u262-b10-linux-x64.tar.gz    //下载jdk8

[root@k8s-master ~]# ll openlogic-openjdk-8u262-b10-linux-x64.tar.gz
-rw-r--r-- 1 root root 104479130 726 2020 openlogic-openjdk-8u262-b10-linux-x64.tar.gz

[root@k8s-master ~]# docker ps | grep jenkins
2324d2daa74d jenkins/jenkins:lts "/sbin/tini -- /usr/…" 6 weeks ago Up 2 hours 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp jenkins

[root@k8s-master ~]# docker cp openlogic-openjdk-8u262-b10-linux-x64.tar.gz jenkins:/usr/local/ //将下载的jdk拷贝到jenkins容器中

[root@k8s-master ~]# docker exec -it -u root jenkins /bin/bash //进入jenkins容器
root@2324d2daa74d:/# java -version //可以看到现在jenkins容器的jdk版本是11.0.12
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)

root@2324d2daa74d:/# cd /usr/local/

root@2324d2daa74d:/usr/local# tar -xvf openlogic-openjdk-8u262-b10-linux-x64.tar.gz //解压我们刚才拷贝到jenkins容器中的jdk低版本

root@2324d2daa74d:/usr/local# ls
bin games lib openlogic-openjdk-8u262-b10-linux-64 sbin src
etc include man openlogic-openjdk-8u262-b10-linux-x64.tar.gz share

root@2324d2daa74d:/usr/local# mv openlogic-openjdk-8u262-b10-linux-64/ jdk8 //将解压后的jdk低版本目录名称修改为jdk8

root@2324d2daa74d:/usr/local# ls
bin etc games include jdk8 lib man openlogic-openjdk-8u262-b10-linux-x64.tar.gz sbin share src

root@2324d2daa74d:/usr/local# whereis java //查看jenkins容器中的java安装位置
java: /opt/java/openjdk/bin/java

root@2324d2daa74d:/usr/local# mv /opt/java/openjdk/bin/java /opt/java/openjdk/bin/java11.bak //备份jenkins容器中的原java11版本

root@2324d2daa74d:/usr/local# ln -s /usr/local/jdk8/bin/java /opt/java/openjdk/bin/java //将/usr/local/jdk8/bin/中低版本的java作为/opt/java/openjdk/bin/中的java软连接

root@2324d2daa74d:/usr/local# java -version //查看“替换”后的java版本
openjdk version "1.8.0-262"
OpenJDK Runtime Environment (build 1.8.0-262-b10)
OpenJDK 64-Bit Server VM (build 25.71-b10, mixed mode)

 再次安装ruby-runtime插件,若还是失败,可以在Jenkins首页重启一下再安装即可。(重启Jenkins后ruby-runtime插件默认就会加载成功)

Jenkins容器安装ruby-runtime插件失败报错解决_java_02

Jenkins容器安装ruby-runtime插件失败报错解决_Jenkins_03

 插件安装完成后我们再将Jenkins容器中的Java版本修改回来。(根据情况,也可以不改回来)

root@2324d2daa74d:~# rm -rf /opt/java/openjdk/bin/java    #删除了之前替换的java8

root@2324d2daa74d:~# mv /opt/java/openjdk/bin/java11.bak /opt/java/openjdk/bin/java #换回了java11

root@2324d2daa74d:~# java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)

↓↓↓↓↓↓

 ​最近刚申请了个微信公众号,上面也会分享一些运维知识,大家点点发财手关注一波,感谢大家。​ ​​【原创公众号】:非著名运维 【福利】:公众号回复 “资料” 送运维自学资料大礼包哦!​

Jenkins容器安装ruby-runtime插件失败报错解决_Jenkins_04