学无止境,气有浩然
前言
工作的时候由于测试环境的Jenkins
坏掉了,想着自己手动搭建一个看看,使用cloudfoundry
,差点没被折磨死。
安装
按照脚本来
cf push jenkins -f manifest.yml
manifest.yml如下:
---
applications:
- name: jenkins
routes:
- route: jenkins.com
memory: 2G
instances: 1
path: jenkins.war
buildpacks:
- java_buildpack_offline
env:
JBP_DEFAULT_OPEN_JDK_JRE: '{ jre: { version: 17.+ }}'
问题
人要麻掉了,官网上显示其实是可以使用这种的,但是构建上去就是报错
024-03-20T14:09:45.536+08:00 [APP/PROC/WEB/0] [OUT] JVM Memory Configuration: -Xmx3529720K -Xss1M -XX:ReservedCodeCacheSize=240M -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=152583K
2024-03-20T14:09:48.194+08:00 [APP/PROC/WEB/0] [ERR] ZipFile.name trick did not work, using fallback: java.lang.ClassCastException: class sun.net.www.protocol.file.FileURLConnection cannot be cast to class java.net.JarURLConnection (sun.net.www.protocol.file.FileURLConnection and java.net.JarURLConnection are in module java.base of loader 'bootstrap')
2024-03-20T14:09:48.312+08:00 [APP/PROC/WEB/0] [OUT] Running from: /home/vcap/tmp/jenkins11504501778207486124.jar
2024-03-20T14:09:48.314+08:00 [APP/PROC/WEB/0] [OUT] webroot: /home/vcap/.jenkins/war
2024-03-20T14:09:48.661+08:00 [APP/PROC/WEB/0] [ERR] 2024-03-20 06:09:48.601+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2024-03-20T14:09:48.664+08:00 [APP/PROC/WEB/0] [ERR] 2024-03-20 06:09:48.664+0000 [id=1] INFO winstone.Logger#logInternal: Jetty shutdown successfully
2024-03-20T14:09:48.664+08:00 [APP/PROC/WEB/0] [ERR] java.util.zip.ZipException: zip END header not found
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at java.base/java.util.zip.ZipFile$Source.findEND(Unknown Source)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at java.base/java.util.zip.ZipFile$Source.initCEN(Unknown Source)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at java.base/java.util.zip.ZipFile$Source.<init>(Unknown Source)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at java.base/java.util.zip.ZipFile$Source.get(Unknown Source)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at java.base/java.util.zip.ZipFile$CleanableResource.<init>(Unknown Source)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at java.base/java.util.zip.ZipFile.<init>(Unknown Source)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at java.base/java.util.zip.ZipFile.<init>(Unknown Source)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at java.base/java.util.jar.JarFile.<init>(Unknown Source)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at java.base/java.util.jar.JarFile.<init>(Unknown Source)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at java.base/java.util.jar.JarFile.<init>(Unknown Source)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at winstone.HostConfiguration.getWebRoot(HostConfiguration.java:277)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at winstone.HostConfiguration.<init>(HostConfiguration.java:88)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at winstone.HostGroup.initHost(HostGroup.java:66)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at winstone.HostGroup.<init>(HostGroup.java:45)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at winstone.Launcher.<init>(Launcher.java:188)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at winstone.Launcher.main(Launcher.java:492)
2024-03-20T14:09:48.665+08:00 [APP/PROC/WEB/0] [ERR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2024-03-20T14:09:48.666+08:00 [APP/PROC/WEB/0] [ERR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2024-03-20T14:09:48.666+08:00 [APP/PROC/WEB/0] [ERR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2024-03-20T14:09:48.666+08:00 [APP/PROC/WEB/0] [ERR] at java.base/java.lang.reflect.Method.invoke(Unknown Source)
2024-03-20T14:09:48.666+08:00 [APP/PROC/WEB/0] [ERR] at executable.Main.main(Main.java:347)
2024-03-20T14:09:48.667+08:00 [APP/PROC/WEB/0] [ERR] 2024-03-20 06:09:48.665+0000 [id=1] SEVERE winstone.Logger#logInternal: Container startup failed
解决
java_buildpack_offline
这种构建方式,在war包上传上去就已经被解压了。所以在执行的时候就会报错,因为找不到这个war
包了。我们可以换一种思路。
Jenkins
提供的war
包是可以脱离tomcat
独立运行的。原因就是因为集成了jetty
,就在在目录executable
里面的winstone.jar
,那我们直接运行这个jar
不就行了,查看运行说明。
java -jar winstone.jar
Required options: either --webroot OR --warfile OR --webappsDir OR --hostsDir
--webroot = set document root folder
那看起来我们只需要加上--webroot
执行当前目录其实就可以了。
cf push jenkins -f manifest.yml --start-command="java -jar executable/winstone.jar --webroot="./""
只要思想不滑坡,办法总比困难多!