Reputation: 6441
I have a TeamCity Build Configuration which runs tests during the night on a large amount of machines. It is important that these tests do not run during the day.
The Build is kicked off with a Schedule Trigger which fires at 1am each day. I have set the Build to time out if it runs for longer than 6 hours, so it stops at around 7am.
I looked at the latest Build this morning and found that the associated Build Agent was unavailable; therefore the Build was still queued.
Had the Build Agent become available, say, at 6am, then I assume the queued Build would have kicked off and continued to run until 11am. I do not want the Build to be running after 7am.
Is there any way I can prevent a Build from starting if it has been queued for too long?
Or, is it possible to stop a Build dead at a particular time? In this case I would also need to prevent the Build from starting in the first place, if it was queued beyond 7am.
Upvotes: 1
Views: 422
Reputation: 161012
I have a build chain that had similar requirements. My solution was to have a separate build configuration that was triggered by a schedule timer.
The only responsibility of this build configuration was to see if all requirements were met (e.g. clock time in your case), and only then finish successfully - the successful finish of this would then trigger the "real" build chain - you can use a Finish Build Trigger for this with the condition of "Trigger after successful build only".
If, on the other hand the requirements are not met, fail the build and the build chain will not run.
The implementation of this "Check and Trigger" build configuration can be just a few lines of powershell:
$time = Get-Date
if($time.Hour -gt 6)
{
exit 1 #failing this build
}
Upvotes: 1