Question
Is it possible to trigger the next build in the build chain with a delay, not immediately?
Answer
There are multiple options to trigger the next build after the monitored build finishes.
Finish Build Trigger will trigger the next build immediately, there is no delay or a quiet period option (see A delay or quiet period for Finish Build Trigger).
It is possible to trigger the next build with a REST API request to the buildQueue endpoint in the last build step of the build configuration. However, it's not possible to schedule a build when triggering it via REST API (see Trigger a scheduled build via rest api). This means that to add a delay before triggering the next build, a sleep command or similar will need to be added before the REST API call, making the agent busy for the whole duration of a delay.
Workaround
The following example applies to Windows build agents, but the same logic can be implemented for other operating systems with different tools.
- Prepare the PowerShell script that will
Start-Sleep <duration>first and then trigger the build with REST API and save it as a.ps1file. - Add the Command Line build step as a final build step in your build configuration.
- Use
start powershell -File <Path to PS script>command in the Command Line build runner to start a separate PowerShell process. - The build will be finished as soon as the command is executed, without the need to wait for the PS script to be finished.
- PS script will trigger a new build after the delay.
Comments
0 comments
Please sign in to leave a comment.