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.
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:
- name: Step name
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:
- name: Checkout code
- name: Run tests
run: make test
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.
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.