GitHub Actions Workflow Syntax: ‘timeout-minutes’ – Controlling Your Job Duration

GitHub Actions Workflow Syntax: ‘timeout-minutes’ – Controlling Your Job Duration

In the comprehensive arena of GitHub Actions, the ‘timeout-minutes’ keyword is an essential control mechanism to manage the execution time of jobs. In this blog post, we will delve into the ‘timeout-minutes’ keyword in the GitHub Actions Workflow syntax, and discuss its syntax, usage, and offer examples for better understanding.

Introduction

GitHub Actions Workflow is a powerful system for automating tasks such as building, testing, and deploying software. Workflows are composed of ‘jobs’ that contain ‘steps’. For managing the execution time of these jobs, the ‘timeout-minutes’ keyword can be a helpful tool.

Understanding the ‘timeout-minutes’ Syntax

In the GitHub Actions Workflow syntax, the ‘timeout-minutes’ keyword is used within a job to set a timeout for that job.

Here is the basic structure of how ‘timeout-minutes’ is used within a job:

In this syntax, ‘number_of_minutes’ is an integer value specifying the maximum duration that the job is allowed to run. If the job hasn’t finished in that time, it will be terminated.

Example of ‘timeout-minutes’ in a Workflow

To illustrate the ‘timeout-minutes’ keyword, let’s consider a workflow that runs a series of tests:

In this workflow, the ‘build’ job consists of two steps. The ‘timeout-minutes’ keyword is set to 15, meaning the job is allowed to run for up to 15 minutes. If the tests take longer than 15 minutes to complete, the job will be terminated.

Conclusion

The ‘timeout-minutes’ keyword in the GitHub Actions Workflow syntax provides developers a valuable tool to control job durations. This allows for improved resource usage, cost management, and prevents jobs from running indefinitely due to errors or inefficient code.