test { useJUnitPlatform() exclude '**/**IgnoreTest.class'// 如果有 test case 不通过,如有必要可以通过这样忽略掉 finalizedBy jacocoTestReport // report is always generated after tests run }
jacocoTestReport { dependsOn test // tests are required to run before generating the report reports { xml.enabled true csv.enabled false html.destination file("${buildDir}/reports/jacoco") } }
执行测试,生成代码覆盖率报告
然后执行 gradle test 就可以了。之后可以可以在 build\reports\jacoco 目录下找到报告了。
When you use Jenkins multibranch pipeline, you may want to have different default parameters settings for defferent branches build.
For example:
For develop/hotfix/release branches, except regular build, you also want to do some code analyzes, like code scanning, etc. For other branches, like feature/bugfix or Pull Request that you just want to do a regular build.
So you need to have dynamic parameter settings for your multibranch pipeline job.
Today, when I tried to upgrade my team’s Jenkins server from Jenkins 2.235.1 to Jenkins 2.263.3, I met a problem that can not launch the Windows agent.
[2021-01-29 23:50:40] [windows-agents] Connecting to xxx.xxx.xxx.xxx <!-- more --> Checking if Java exists java -version returned 11.0.2. [2021-01-29 23:50:40] [windows-agents] Installing the Jenkins agent service [2021-01-29 23:50:40] [windows-agents] Copying jenkins-agent.exe ERROR: Unexpected error in launching an agent. This is probably a bug in Jenkins Also: java.lang.Throwable: launched here at hudson.slaves.SlaveComputer._connect(SlaveComputer.java:286) at hudson.model.Computer.connect(Computer.java:435) at hudson.slaves.SlaveComputer.doLaunchSlaveAgent(SlaveComputer.java:790) ... ... at java.lang.Thread.run(Thread.java:748) java.lang.NullPointerException at hudson.os.windows.ManagedWindowsServiceLauncher.launch(ManagedWindowsServiceLauncher.java:298)
[2021-01-30 23:53:40] [windows-agents] Connecting to xxx.xxx.xxx.xxx Checking if Java exists java -version returned 11.0.2. [2021-01-30 23:53:47] [windows-agents] Copying jenkins-agent.xml [2021-01-30 23:53:48] [windows-agents] Copying agent.jar [2021-01-30 23:53:48] [windows-agents] Starting the service ERROR: Unexpected error in launching an agent. This is probably a bug in Jenkins org.jinterop.dcom.common.JIException: Unknown Failure at org.jvnet.hudson.wmi.Win32Service$Implementation.start(Win32Service.java:149) Caused: java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor219.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.kohsuke.jinterop.JInteropInvocationHandler.invoke(JInteropInvocationHandler.java:140) Also: java.lang.Throwable: launched here
Then change jenkins-agent.exe.config file. remove or comment out this line <supportedRuntime version="v2.0.50727" /> as below
also do this for jenkins-slave.exe.config in case it also exists.
<configuration> <runtime> <!-- see http://support.microsoft.com/kb/936707 --> <generatePublisherEvidenceenabled="false"/> </runtime> <startup> <!-- this can be hosted either on .NET 2.0 or 4.0 --> <!-- <supportedRuntime version="v2.0.50727" /> --> <supportedRuntimeversion="v4.0" /> </startup> </configuration>
Then try to Launch agent.
If it still does not work and has this error message “.NET Framework 2.0 or later is required on this computer to run a Jenkins agent as a Windows service”, you need to upgrade your .NET Framework.
I believe most of you have used the Jenkins configuration as code principle, so you build/test/release process will be described in code.
It looks like all is good, but not all of the configuration is in code, same of the Jenkins system configuration is store in the Jenkins service, so we also need to backup Jenkins in case of any disaster.
There are two ways to backup Jenkins, one used Jenkins plugin, the other is create shell scripts.
Using plug-in backup
I used the ThinBackup plugin, here is my thinBackup configuration.