5

I would like to check for or get notifications about SCM poll failures in Jenkins (for example, when the repository URL had changed, or branch got deleted). I thought about these:

a) A Jenkins console script, which would list such faulty jobs

b) Configuring/installing plugin for Jenkins to notify me somehow about that fact (e-mail, anything)

c) External script/executable (bash, python, ...), which would list builds which failed in last X hours due to SCM poll failure

Veelkoov
  • 1,366
  • 14
  • 26
  • 1
    [This answer](http://stackoverflow.com/questions/18277720/email-notification-for-subversion-polling-failures-in-jenkins) is for SVN, but I think it applies in this case as well. – approxiblue Jun 13 '16 at 16:26

1 Answers1

2

As you mentioned in your question, one way to tackle this problem is by using a script. For example, Groovy Postbuild.

Since Groovy Postbuild scripts run on the master, you can access each job's scm-polling.log found on the file system using standard IO functions.

For example, assuming a Windows master, here is some (untested) pseudocode to give you some ideas:

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();
}

Once you have marked the build as failure, you can use the standard email functionality of Jenkins to send an email or format it to look nice using the Email-ext plugin.

Daniel Omoto
  • 2,431
  • 17
  • 15