Flutter analyze result on Jenkins

354 views Asked by At

Is there a way to show the result of

flutter analyze

which is executed during a Jenkins build on the result page, like e.g. this graph for Android:

static analysis android

Can we use the Warnings-NG plugin with recordIssues-function? How to configure the function?

1

There are 1 answers

0
Christopher On BEST ANSWER

I solved the issue by configuring a custom Groovy Parser as described here:

  1. Goto Manage Jenkins -> System -> Section "Groovy Based Warnings Parsers"
  2. Click on Add
  3. Configure:

Name and ID are arbitrary values. Regular Expression: ^\[(.*)\] (.*) \((.*):(\d*):(\d*)\) Mapping Script:

import edu.hm.hafner.analysis.Severity

String message = matcher.group(2)
String file = matcher.group(3)

return builder
    .setFileName(file)
    .setMessage(message)
    .setCategory("flutter")
    .setLineStart(Integer.parseInt(matcher.group(4)))
    .setSeverity(Severity.WARNING_NORMAL) 
    .buildOptional();

Example Log Message:

[info] Missing a required trailing comma (/Users/user/Development/CICD/template-flutter/lib/main.dart:55:13)
[info] Missing a required trailing comma (/Users/user/Development/CICD/template-flutter/lib/main.dart:105:16)

Save the changes.

Using the Groovy Parser:

In your Jenkinsfile add this for declarative pipelines:

stage('Static Analysis'){
    steps {
        sh label: 'flutter analyze', script: 'fvm flutter analyze --write=flutter_analyze_report.txt || true'
    }
    post {
        always {
            recordIssues(tools: [groovyScript(id: 'flutter-analyze', name: 'Flutter Analyze', parserId: '<the id you have configured in system settings>', pattern: '**/flutter_analyze_report.txt')])
        }
    }
}