How to set a custom maximum job duration

Currently the maximum duration of a job is "hard-coded" at the organization level, and is solely based on the organization's plan.

This article explains how to leverage the step-level background attribute and the CircleCI API v2 "Cancel job" endpoint to customize a job's maximum duration.



You will need to store a personal API token (it can be a personal API token generated for a machine-user) in a project-level or context-level environment variable.



Add the following as the first step of your job:

- run:
name: Set maximum job duration to 90 minutes
background: true
command: |
sleep 90m
curl --request POST \
--header "Circle-Token: $CIRCLECI_API_TOKEN"

Note: CIRCLE_PROJECT_USERNAME, CIRCLE_PROJECT_REPONAME, and CIRCLE_BUILD_NUM, are built-in environment variables, and are automatically populated for each job.

Was this article helpful?
0 out of 1 found this helpful



Article is closed for comments.