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.[email protected]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.[email protected]74f6c8f3]: org.s[email protected]2ea4e5b4 
[2020-05-29 10:51:04] [信息     ] Pre-instantiating singletons in org.s[email protected]2ea4e5b4: defining beans [authenticationManager,activeDirectory]; root of factory hierarchy 
[2020-05-29 10:51:04] [信息     ] Refreshing org.[email protected]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.[email protected]98ee1ca]: org.s[email protected]10dd10a4 
[2020-05-29 10:51:04] [信息     ] Pre-instantiating singletons in org.s[email protected]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.[email protected]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.[email protected]5ecd14f5]: org.s[email protected]77d7621d
5月 29, 2020 10:50:05 上午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.s[email protected]77d7621d: defining beans [authenticationManager,activeDirectory]; root of factory hierarchy
5月 29, 2020 10:50:05 上午 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.[email protected]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.[email protected]76a19a9d]: org.s[email protected]62a27a6f
5月 29, 2020 10:50:05 上午 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.s[email protected]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包了.


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