Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notify about / check for SCM poll failure in Jenkins

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

like image 661
Veelkoov Avatar asked Nov 09 '22 14:11

Veelkoov


1 Answers

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.

like image 193
Daniel Omoto Avatar answered Nov 15 '22 07:11

Daniel Omoto