about 4 years ago

首先,要在 Jenkins 上安裝 Warning Plugin

接著,到 Jenkins -> Configuration System 的 Compiler Warnings 區塊 新增一個 Parser,設定如下:

Name (套件的名字)
Flake8
Link name (連結的文字)
Flake8
Trend report name (圖表的標題)
Flake8
Regular Expression
^(.*):([0-9]*):([0-9]*):\ (\w{4})\ (.*)$
Mapping Script
import hudson.plugins.warnings.parser.Warning
import hudson.plugins.analysis.util.model.Priority

String fileName = matcher.group(1)
String type = matcher.group(4)
String lineNumber = matcher.group(2)
String message = matcher.group(5)
String typeCategory = String.valueOf(type.charAt(0));
String category
Priority priority = Priority.NORMAL

switch (typeCategory) {
    case "E":
        category = "PEP8 Errors"
        priority = Priority.HIGH
        break
    case "W":
        category = "PEP8 Warnings"
        break
    case "F":
        category = "PyFlakes Warnings"
        break
    case "C":
        category = "McCabe Warnings"
        break
    case "N":
        category = "Naming Conventions Errors"
        break
    default:
        category = "Unkown Warnings/Errors"
        priority = Priority.LOW
}
return new Warning(fileName, Integer.parseInt(lineNumber), type, category, message, priority)

最後,在你要使用的工作 (Job),新增一個 post-build action: Scan for compiler warnings。在此區塊選擇來源,並將 Parser 設定為剛剛新增的 Flake8 即可。

參考資料

  1. Jenkins Code Analysis
  2. Flake8 Warnings
← Ansible 劇本 自製離線版 Package Repository →
 
comments powered by Disqus