jenkins学习之Jenkins调试和插件调试

Jenkins调试和插件调试



运行 
如果是在 Jenkins core 的源码目录下的话,需要进入到 war 目录;如果是插件的话,通常在根目录下执行:

mvn hpi:run

程序正常启动后,会在 target 下生成一个运行时的目录:会有个work目录,充当 JENKINS_HOME 目录.
插件的是在 当前目录 下面 有个work/ 目录.
jenkins 的话会在war子目录下面有个work/ 目录.

新版本的jenkins编译使用下面命令
mvn -am -pl war,bom -DskipTests -Dspotbugs.skip clean package
新版本的jenkins的运行使用下面命令
mvn -pl war jetty:run



旧版本的jenkins编译:
mvn -am -pl war -DskipTests -Dfindbugs.skip clean package
旧版本的jenkins运行
mvn -pl war hudson-dev:run


jenkins编译调试
jenkins 2.222.1 版本 
mvn -am -pl war,bom -DskipTests -Dspotbugs.skip clean package
mvn -pl war jetty:run

jenkins 2.176.1 版本
mvn clean package -pl war -am -DskipTests -Dfindbugs.skip
mvn -pl war hudson-dev:run


跳过测试 
mvn hpi:run -DskipTests 该命令会跳过测试的执行,但还是会编译测试代码的。如果确实想要加快构建速度而跳过测试的话,建议使用这个命令,而不是下面的:

mvn hpi:run -Dmaven.test.skip=true 该命令既不执行测试代码,也不会编译。


指定端口 

mvn hpi:run -Djetty.port=1234

mvn hpi:run -Djenkins.install.runSetupWizard=true




指定 Jenkins 版本
mvn hpi:run -Djenkins.version=2.121.1


指定 log 格式
mvn -DskipTests=true -Djava.util.logging.config.file=logging.properties package hpi:run

新建个 logging.properties  文件,内容如下 (这个日志配置文件内容 摘自 https://www.logicbig.com/tutorials/core-java-tutorial/logging/customizing-default-format.html 这里)
handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=[%1$tF %1$tT] [%4$-7s] %5$s %n
然后输出的日志格式如下:
[2020-05-29 10:51:02] [信息     ] Started initialization 
[2020-05-29 10:51:02] [信息     ] Listed all plugins 
[2020-05-29 10:51:03] [信息     ] Prepared all plugins 
[2020-05-29 10:51:03] [信息     ] Started all plugins 
[2020-05-29 10:51:03] [信息     ] Augmented all extensions 
[2020-05-29 10:51:03] [信息     ] Loaded all jobs 
[2020-05-29 10:51:03] [信息     ] Started Download metadata 
[2020-05-29 10:51:03] [信息     ] Finished Download metadata. 3 ms 
[2020-05-29 10:51:04] [信息     ] Refreshing org.springframework.web.context.support.StaticWebApplicationContext@74f6c8f3: display name [Root WebApplicationContext]; startup date [Fri May 29 10:51:04 CST 2020]; root of context hierarchy 
[2020-05-29 10:51:04] [信息     ] Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@74f6c8f3]: org.springframework.beans.factory.support.DefaultListableBeanFactory@2ea4e5b4 
[2020-05-29 10:51:04] [信息     ] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2ea4e5b4: defining beans [authenticationManager,activeDirectory]; root of factory hierarchy 
[2020-05-29 10:51:04] [信息     ] Refreshing org.springframework.web.context.support.StaticWebApplicationContext@98ee1ca: display name [Root WebApplicationContext]; startup date [Fri May 29 10:51:04 CST 2020]; root of context hierarchy 
[2020-05-29 10:51:04] [信息     ] Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@98ee1ca]: org.springframework.beans.factory.support.DefaultListableBeanFactory@10dd10a4 
[2020-05-29 10:51:04] [信息     ] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@10dd10a4: defining beans [filter,legacy]; root of factory hierarchy 
[2020-05-29 10:51:04] [信息     ] Install state transitioning from: DEVELOPMENT to : DEVELOPMENT 
[2020-05-29 10:51:04] [信息     ] Completed initialization 
[2020-05-29 10:51:04] [信息     ] Jenkins is fully up and running 

 jenkins 默认的  logging.properties  文件,内容如下  (https://wiki.jenkins.io/display/JENKINS/custom+log+formatter+for+hpi-run)
 handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = org.example.SingleLineFormatter
然后输出的日志格式如下:
5月 29, 2020 10:50:03 上午 jenkins.InitReactorRunner$1 onAttained
信息: Started initialization
5月 29, 2020 10:50:03 上午 jenkins.InitReactorRunner$1 onAttained
信息: Listed all plugins
5月 29, 2020 10:50:04 上午 jenkins.InitReactorRunner$1 onAttained
信息: Prepared all plugins
5月 29, 2020 10:50:04 上午 jenkins.InitReactorRunner$1 onAttained
信息: Started all plugins
5月 29, 2020 10:50:04 上午 jenkins.InitReactorRunner$1 onAttained
信息: Augmented all extensions
5月 29, 2020 10:50:04 上午 jenkins.InitReactorRunner$1 onAttained
信息: Loaded all jobs
5月 29, 2020 10:50:04 上午 hudson.model.AsyncPeriodicWork$1 run
信息: Started Download metadata
5月 29, 2020 10:50:04 上午 hudson.model.AsyncPeriodicWork$1 run
信息: Finished Download metadata. 25 ms
5月 29, 2020 10:50:05 上午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@5ecd14f5: display name [Root WebApplicationContext]; startup date [Fri May 29 10:50:05 CST 2020]; root of context hierarchy
5月 29, 2020 10:50:05 上午 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
信息: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@5ecd14f5]: org.springframework.beans.factory.support.DefaultListableBeanFactory@77d7621d
5月 29, 2020 10:50:05 上午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@77d7621d: defining beans [authenticationManager,activeDirectory]; root of factory hierarchy
5月 29, 2020 10:50:05 上午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@76a19a9d: display name [Root WebApplicationContext]; startup date [Fri May 29 10:50:05 CST 2020]; root of context hierarchy
5月 29, 2020 10:50:05 上午 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
信息: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@76a19a9d]: org.springframework.beans.factory.support.DefaultListableBeanFactory@62a27a6f
5月 29, 2020 10:50:05 上午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@62a27a6f: defining beans [filter,legacy]; root of factory hierarchy
5月 29, 2020 10:50:05 上午 jenkins.model.Jenkins setInstallState
信息: Install state transitioning from: DEVELOPMENT to : DEVELOPMENT
5月 29, 2020 10:50:05 上午 jenkins.InitReactorRunner$1 onAttained
信息: Completed initialization
5月 29, 2020 10:50:05 上午 hudson.WebAppMain$3 run
信息: Jenkins is fully up and running


https://jenkinsci.github.io/maven-hpi-plugin/run-mojo.html

jenkins编译好的的war包需要签名, 使用如下命令验证签名信息
 jarsigner -verbose -certs -verify jenkins.war
 

$ jarsigner -verbose -certs -verify /usr/share/jenkins/jenkins.war

s     150038 Mon Mar 23 10:58:26 UTC 2020 META-INF/MANIFEST.MF

      >>> Signer
      X.509, CN=Infradna Inc (Kohsuke Kawaguchi), O=Infradna Inc (Kohsuke Kawaguchi), STREET=4438 Hilton Ave, L=San Jose, ST=California, OID.2.5.4.17=95130, C=US
      [certificate is valid from 7/23/15 12:00 AM to 7/22/20 11:59 PM]
      X.509, CN=COMODO RSA Code Signing CA, O=COMODO CA Limited, L=Salford, ST=Greater Manchester, C=GB
      [certificate is valid from 5/9/13 12:00 AM to 5/8/28 11:59 PM]
      X.509, CN=COMODO RSA Certification Authority, O=COMODO CA Limited, L=Salford, ST=Greater Manchester, C=GB
      [certificate is valid from 5/30/00 10:48 AM to 5/30/20 10:48 AM]
      X.509, CN=AddTrust External CA Root, OU=AddTrust External TTP Network, O=AddTrust AB, C=SE
      [trusted certificate]
      >>> TSA
      X.509, CN="Sectigo RSA Time Stamping Signer #1", O=Sectigo Limited, L=Salford, ST=Greater Manchester, C=GB
      [certificate is valid from 5/2/19 12:00 AM to 8/1/30 11:59 PM]
      X.509, CN=Sectigo RSA Time Stamping CA, O=Sectigo Limited, L=Salford, ST=Greater Manchester, C=GB
      [certificate is valid from 5/2/19 12:00 AM to 1/18/38 11:59 PM]


显示的签名信息 如果是 Kohsuke Kawaguchi 这个人的就表示是官方的war包了.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章