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:
Can we use the Warnings-NG plugin with recordIssues
-function? How to configure the function?
I solved the issue by configuring a custom Groovy Parser as described here:
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.
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')])
}
}
}