Jenkins如何更新Build Jobs的Weather报告?

时间:2017-04-26 06:34:55

标签: jenkins

Jenkins遵循哪些机制/统计数据来更新有关构建工作的天气信息?

Jenkins Weather Dashboard

1 个答案:

答案 0 :(得分:2)

查看https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/model/HealthReport.java

然后您可以在那里找到以下代码:

// These are now 0-20, 21-40, 41-60, 61-80, 81+ but filenames unchanged for compatibility
private static final String HEALTH_OVER_80 = "icon-health-80plus";
private static final String HEALTH_61_TO_80 = "icon-health-60to79";
private static final String HEALTH_41_TO_60 = "icon-health-40to59";
private static final String HEALTH_21_TO_40 = "icon-health-20to39";
private static final String HEALTH_0_TO_20 = "icon-health-00to19";

private static final String HEALTH_OVER_80_IMG = "health-80plus.png";
private static final String HEALTH_61_TO_80_IMG = "health-60to79.png";
private static final String HEALTH_41_TO_60_IMG = "health-40to59.png";
private static final String HEALTH_21_TO_40_IMG = "health-20to39.png";
private static final String HEALTH_0_TO_20_IMG = "health-00to19.png";
private static final String HEALTH_UNKNOWN_IMG = "empty.png";

代码表示如果您的成功构建超过80%,您将看到晴朗的天气图标。

如果您的成功构建介于60%-79%之间,您会看到一个名为health-60to79的图片。

...

您可以在https://github.com/jenkinsci/jenkins/blob/master/war/images找到图片。它们的名称为health-00to19.svghealth-20to39.svghealth-40to59.svghealth-60to79.svghealth-80plus.svg

HealthReport是用于更新天气图标的机制

public HealthReport(int score, String iconUrl, Localizable description) {
    this.score = score;
    if (score <= 20) {
        this.iconClassName = HEALTH_0_TO_20;
    } else if (score <= 40) {
        this.iconClassName = HEALTH_21_TO_40;
    } else if (score <= 60) {
        this.iconClassName = HEALTH_41_TO_60;
    } else if (score <= 80) {
        this.iconClassName = HEALTH_61_TO_80;
    } else {
        this.iconClassName = HEALTH_OVER_80;
    }
    if (iconUrl == null) {
        if (score <= 20) {
            this.iconUrl = HEALTH_0_TO_20_IMG;
        } else if (score <= 40) {
            this.iconUrl = HEALTH_21_TO_40_IMG;
        } else if (score <= 60) {
            this.iconUrl = HEALTH_41_TO_60_IMG;
        } else if (score <= 80) {
            this.iconUrl = HEALTH_61_TO_80_IMG;
        } else {
            this.iconUrl = HEALTH_OVER_80_IMG;
        }
    } else {
        this.iconUrl = iconUrl;
    }
    this.description = null;
    setLocalizibleDescription(description);
}