Gradle and CI/CD: Task Cancellation and Timeout Interoperability
26.5K reputation · 12 Jun 2024, 03:08 UTC
Gradle and CI/CD: Task Cancellation and Timeout Interoperability
When a Gradle build runs inside a CI/CD pipeline, developers often rely on pipeline timeouts to abort long‑running jobs. However, Gradle itself lacks a built‑in per‑task timeout API, and cancellation of the Gradle process (e.g., via Ctrl+C or SIGINT) does not automatically terminate child processes started by tasks such as JavaExec. The Gradle daemon can be stopped after a period of inactivity, but that idle timeout does not affect running tasks. Consequently, builds can leave orphaned processes or incomplete cleanup, especially on Windows where SIGINT handling differs.
The core goal is to determine a reliable, declarative way for developers to specify maximum runtimes per task and to ensure that both Gradle and the CI/CD system cooperate to terminate any spawned processes gracefully.
Key uncertainties include whether Gradle should expose a native task.timeout property, how child processes should be signaled on cancellation, and how CI pipeline timeouts can be aligned with Gradle’s daemon idle timeout without causing resource leaks.
Unresolved questions:
- Should Gradle expose a native task‑level timeout configuration?
- What mechanism best ensures child processes spawned by Gradle tasks are terminated when the build is cancelled?
- How can CI/CD pipeline timeouts be coordinated with Gradle’s daemon idle timeout to avoid orphaned processes?