sensu-plugins / sensu-plugins-jenkins

This plugin provides native Jenkins instrumentation for monitoring and metrics collection, including: health, job status, metrics via `JQS`, and others.
http://sensu-plugins.io
MIT License
9 stars 18 forks source link

Fix issue when multiple builds are currently running #36

Closed CoRfr closed 6 years ago

CoRfr commented 6 years ago

When checking the status of a build, and it is in a 'running' state, it would check the previous build. However there is not guarantee that this build is not running as well, which results in a build['result'] that is nil, and an exception.

This uses the 'lastCompletedBuild' alias to get the last completed build, since we are sure that this one is not running.

Pull Request Checklist

Is this in reference to an existing issue?

General

New Plugins

Purpose

Known Compatibility Issues

CoRfr commented 6 years ago

Otherwise in term of testing:

Last build OK:

check-jenkins-job-status.rb -u 'http://jenkins-cnt:8080/' --jobs '^Legato-Review'
JenkinsJobChecker OK: All queried jobs report success

Build in progress, last build not OK:

check-jenkins-job-status.rb -u 'http://jenkins-cnt:8080/' --jobs '^Mdm9x28-Review'
JenkinsJobChecker CRITICAL: Jobs reporting failure: Mdm9x28-Review, jobs reported as unstable:

Build finished and not OK:

docker exec -ti sensu-client check-jenkins-job-status.rb -u 'http://jenkins-cnt:8080/' --jobs '^Mdm9x15-GenerateManifest'
JenkinsJobChecker CRITICAL: Jobs reporting failure: Mdm9x15-GenerateManifest, jobs reported as unstable:
majormoses commented 6 years ago

Sorry this got lost in the sea of github notifications. Will review latest comments and code shortly.

majormoses commented 6 years ago

released: https://rubygems.org/gems/sensu-plugins-jenkins/versions/1.7.1