在Jenkins中通知/检查SCM轮询失败

Fox*_*ion 5 version-control scripting polling jenkins

我想在Jenkins中检查或获取有关SCM轮询失败的通知(例如,当存储库URL已更改或分支被删除时).我想到了这些:

a)Jenkins控制台脚本,它将列出这些错误的工作

b)为Jenkins配置/安装插件以某种方式通知我这个事实(电子邮件,任何东西)

c)外部脚本/可执行文件(bash,python,...),它将列出由于SCM轮询失败而在过去X小时内失败的构建

Dan*_*oto 2

正如您在问题中提到的,解决此问题的一种方法是使用脚本。例如,Groovy Postbuild

由于 Groovy Postbuild 脚本在主服务器上运行,因此您可以使用标准 IO 函数访问文件系统上找到的每个作业的 scm-polling.log。

例如,假设您是 Windows 高手,这里有一些(未经测试的)伪代码可以为您提供一些想法:

def error = false;
def jobsDirectory = new File("C:\\Jenkins\\jobs");
jobsDirectory.eachFile { 
    def pollingLog = new File(it.path + "\\scm-polling.log");
    if(pollingLog.text =~ "ERROR")
    {
        manager.listener.logger.println(it.path + " has polling errors.");
        error = true;
    }
}

if(error) {
    manager.build.buildFailure();
}
Run Code Online (Sandbox Code Playgroud)

将构建标记为失败后,您可以使用 Jenkins 的标准电子邮件功能发送电子邮件或使用Email-ext 插件将其格式化为看起来不错。