Build configuration "time in failed state" ranking

I'd like to build a plugin that tracks the amount of time each build configuration is in a failed state so I can rank them accordingly in a report.  First, is there an existing solution?
If I need to write a plugin, can you suggest an approach that might be best?  At the moment, the only solution I can think of is to accept notifications of success vs failure with a custom notifier and track these as events in order to generate the statistics I'm interested in.  Is there a better way?  Is that data already tracked by TeamCity?

4 comments

Leon,

The first question is what will be output of the plugin? Do you plan to provide a web UI page with the data?

Out of the box this kind of statistics is not available.

It seems you can grab history of build for each build configuration and then go down the history finding the last successful build and then sort the build configurations by the time between the last build and last successful build.

I would consider something like:
    void example(ProjectManager manager) {
        final List<SBuildType> activeBuildTypes = manager.getActiveBuildTypes();
        for (SBuildType buildType : activeBuildTypes) {
            try {
                final long timeInFailureInSeconds = (buildType.getLastChangesFinished().getStartDate().getTime() - buildType.getLastChangesSuccessfullyFinished().getStartDate().getTime())/1000;
            } catch (NullPointerException e) {
                //ignore
            }
        }
    }


BTW, Please consider sharing the plugin with other TeamCity users!

0

Perfect.  I browsed the API last night and came to a less concise, but similar conclusion.  Thanks, this snippet will save us a lot of time.  We will share the plugin when it's complete.




At a minimum we just want a CSV table report generated for us to import into Excel.  We'll probably include it into a formatted UI page later.


Thanks a lot Yegor.

0

Hi Yegor,

As a part of this plugin, we'd like to distinguish between failures that are "internal" to the build configuration and those that are "external". External failures would include any failures that do not indicate a problem with the build configuration itself, but instead indicate a problem with one of the build's upstream dependencies. These failures show in the TeamCity UI as "Failed dependencies: n". What is the appropriate API to identify these build failure types? My first thought was that it would be a separate BuildProblem type, but failures of this type don't appear to have an associated BuildProblem. Does this indicate that for any build for which (build.getBuildStatus().isFailed() && build.getBuildProblems().size == 0), then that build can be assumed to have failed because of a failed dependency? Is there a better way to determine this?

0

Stephen,

Sorry for the delay in replying.
In case this is still actual:

It seems that if you care for the failed dependencies the most obvious way is to go through dependencies and check if they are failed.
At some point we wil probably add a separate type of problem to indicate failed dependencies, but this is not yet available.

You can use SBuild.getBuildPromotion().getDependencies()[X].getDependOn().getAssociatedBuild().getBuildStatus() to go through the statuses of all the dependencies.
The code should not be run under a user session (e.g. when serving a web page) as it will process only the dependencies that user has view permission for.

BTW, did you consider sharing your plugin with other users?
If you choose to do so we can add in on plugins page and setup a build for it on teamcity.jetbrains.com if you have an open repository.

0

Please sign in to leave a comment.