Jenkins调试和插件调试

1
2
3
4
5
6
7
8
9
10
11
12


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

mvn hpi:run

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


jenkins编译调试

1
2
3
4
5
6
7
8
9
10
11
12
13

新版本的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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

jenkins编译调试

jenkins-2.339版本
mvn -am -pl war,bom -DskipTests -Dspotbugs.skip -Dcheckstyle.skip=true clean package install
mvn -pl war jetty:run


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


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

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


1
2
3
4
5
6
7
8
指定端口 

mvn hpi:run -Djetty.port=1234

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



1
2
3
4

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

指定 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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包了.


分支 change-timestyle-for-build-history-entry 改了构建日期现实格式

分支 blackshark-for-jenkins-2.303.1 公司最终使用的一个版本,

1
2
3
4
5
6
7
* c0a786791f * add pattern to formatDate for buildCaption                   <bright..>[2022-08-27 11:52 2022-08-27 11:52] (HEAD, origin/blackshark-for-jenkins-2.303.1)
* 867fb945cc * add pattern to formatDate for build history entry <bright..>[2022-08-27 11:05 2022-08-27 11:05]
* 9f7dfa3a40 * update the buildCaption show displayName to number <bright..>[2021-09-10 14:11 2021-09-10 14:11]
* 2e3b5d1ec2 * permalink update show displayName to number <bright..>[2021-09-10 13:58 2021-09-10 13:58]
* 6033365280 * change the time style to medium for build history entry <bright..>[2021-09-10 12:33 2021-09-10 12:33]
* 9998543c95 * keep fixed length for the delete build button <bright..>[2021-09-10 12:31 2021-09-10 12:31]
* 4180710ea9 * [maven-release-plugin] prepare release jenkins-2.303.1 <Jenkin..>[2021-08-25 10:53 2021-08-25 10:53] (tag: jenkins-2.303.1)

分支 blackshark-for-jenkins-2.291.1

1
2
3
4
* 7dbeff340a * change the time style to medium for build history entry      <Mamh-w..>[2020-09-03 21:17 2021-06-11 08:01] (origin/blackshark-jenkins-2.291.1)
* cf3616c158 * [JENKINS-58157] keep fixed length for the delete build but.. <Mamh-L..>[2019-06-25 13:15 2021-06-11 07:54]
* 3327a86385 * fixup search and filter case sensitive issue in PluginMana.. <Mamh-L..>[2020-10-14 12:53 2021-06-11 07:51]
* 78b24599b9 * [maven-release-plugin] prepare release jenkins-2.291 <Jenkin..>[2021-05-04 12:14 2021-05-04 12:14] (tag: jenkins-2.291)