What is Cobertura
Cobertura is a free Java tool that calculates the percentage of code accessed by tests.
问题
Jenkins中集成了Cobertura,code coverage下降unittest就会fail,尽管设置了unstable rate为60%,当code coverage rate高于60%也会fail.
原因
Jenkins pipeline中我们把failUnstable设置成true了,每次Jenkins任务跑完会把mininum stability设置为本次的code coverage值。如果下次run Jenkins任务code coverage低于上一次的minimum stability,就会报error:
ERROR: [Cobertura] Failing build due to unstability.
Action
把failUnstable设置成false,每次Jenkins任务都会把本次的code coverage设置为health minimum和stability minimum:
Lines's new health minimum is: 78.29
Lines's new stability minimum is: 78.29
不再记录上次的stability minimum。
思考
今天又翻了翻资料才发现实cobertura从1.13升级到1.16以后才有的这个问题,原来cobertura期待的行为是The pipeline job will always use the thresholds set in the Jenkinsfile rather than the updated thresholds from previous builds.
在1.13以后修好了这个bug,我们以为的bug是人家的bugfix。
参考
ref: lineCoverageTargets.
Fix: auto update not works when using Pipeline.