Null build finish date for SRunningBuild that has completed

When creating a notifier plugin, the notifyBuildFailed and notifyBuildSuccessful methods are invoked by the server with an SRunningBuild parameter, presumably these builds have completed. However calling getFinishDate() for these parameters returns null.

Here's the snippet where I am getting the finish date in my plugin:
public BuildAlertPayload(NotificationType type, SRunningBuild build, Set<SUser> alertRecipients) {
...
String buildEndTime = build.getFinishDate() == null ? null : build.getFinishDate().toString();
...
}

The SRunningBuild param is passed in from notifyBuildSuccessful or notifyBuildFailed.

Is this not the proper way to get the completed time?


Relevant java doc:

getFinishDate

 
@Nullable
java.util.Date getFinishDate()
Returns finish timestamp for the build (server time) or
null
if it hasn't been finished yet.

Returns:
Date/time when the build has been finished,
null
if still running.




3 comments

David,

Instance of Runnig build will always return "null" for the finishe date.
What you can do is to find a finished build by the build id and use the found finished build to get related data.
Like buildsManager.findBuildInstanceById(runningBuild.getBuildId())

0

Hi Yegor, sorry for the late reply.

How do I initialize an instance of BuildsManager so that it will work correctly? findBuildInstancesById doesn't appear to be a static method and the class is abstract.

0

I solved this by adding a BuildsManager parameter to my NotificatorAdaptor's constructor - this got picked up by the spring autowiring and I was able to use it to solve my problem as Yegor described.

0

Please sign in to leave a comment.