0

Cobertura plugin in Jenkins has a support of ratcheting by ticking these boxes:

  • Health auto update
  • Stability auto update

When ticking this box, the coverage metric targets (in Jenkins configuration page) will be updated on every successful build: enter image description here

These values will be overridden by job-dsl-plugin when seed job is triggered. How can I retain these values when my seed job is triggered?

ceilfors
  • 2,617
  • 23
  • 33

1 Answers1

0

Seems like I can't find a pretty way to do this right now, but here is my solution.

Solution

1. Execute a Groovy script and store all of the current job cobertura configuration in a JSON file.

Cobertura configuration can be retrieved like:

def coberturaPublisher = project.getPublishersList().get(CoberturaPublisher)
coberturaPublisher.**healthyTarget**.getTarget(**CoverageMetric.METHOD**)

2. job-dsl-plugin to configure cobertura by using the JSON file if it's available

job-dsl's CoberturaContext normal method can't be called here because the data represented in the first step is different with the method parameter:

  • 80% is stored as 8000000 in the JSON file
  • 80% must be passed in as 80 instead of 8000000 to CoberturaContext methods.

As of today, I can't simply divide the value by 100000 because the method is accepting Integer instead of double. To retain the precision of the ratcheted configuration, I have to bypass the validation by manipulating the target directly:

coberturaContext.targets = [
    'METHOD': new CoberturaContext.CoberturaTarget(
        targetType: CoberturaContext.TargetType.METHOD,
        healthyTarget: 8000000,
        unhealthyTarget: previousConfig ? previousConfig.cobertura.method.unhealthy : 0,
        failingTarget: previousConfig ? previousConfig.cobertura.method.failing : 0
    ),

Why bother creating the JSON file while you can call Jenkins API directly?

My seed job is configured with this example here, hence I have an additional classpath used in the job configuration. When I tried to hit Jenkins API directly, I'm getting class loading issue for Cobertura plugin classes.

ceilfors
  • 2,617
  • 23
  • 33