Stay organized with collections
Save and categorize content based on your preferences.
This page describes how to cancel Batch jobs.
Cancel jobs that you want to stop running or prevent from running.
Ideally, you should configure your jobs to automatically stop running and
fail whenever they don't behave as intended. For example, configure your
runnables to return a non-zero exit code or timeout.
But, in practice, you might still want to manually stop unfinished
jobs. For example, cancel a job when you notice you need to troubleshoot or
replace a job that hasn't finished yet.
Like succeeded and failed jobs, a cancelled job remains in your project for up
to 60 days, after which Google Cloud automatically deletes the job. If you
want to cancel a job and don't need to retain the job's information, then you
can immediately delete the job instead.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[[["\u003cp\u003eThis page outlines the process for canceling Batch jobs, which is useful for stopping jobs that are running or preventing jobs from starting.\u003c/p\u003e\n"],["\u003cp\u003eCanceling a job can be done manually, for example, when a job requires troubleshooting, or it should be configured to automatically stop by a non-zero exit code or timeout.\u003c/p\u003e\n"],["\u003cp\u003eTo cancel a job, you need the Batch Job Editor role (\u003ccode\u003eroles/batch.jobsEditor\u003c/code\u003e) and can do so using either the \u003ccode\u003egcloud alpha batch jobs cancel\u003c/code\u003e command in the Google Cloud CLI or the \u003ccode\u003ejobs.cancel\u003c/code\u003e v1alpha method in the Batch API.\u003c/p\u003e\n"],["\u003cp\u003eCancelled jobs, similar to succeeded and failed jobs, remain in the project for 60 days before being automatically deleted by Google Cloud, but you can delete the job immediately to not keep the information if desired.\u003c/p\u003e\n"],["\u003cp\u003eBefore canceling a job, make sure to have enabled Batch and completed the prerequisites, and remember to replace placeholders like \u003ccode\u003eJOB_NAME\u003c/code\u003e and \u003ccode\u003eLOCATION\u003c/code\u003e with your specific job and location details.\u003c/p\u003e\n"]]],[],null,["# Cancel jobs\n\nThis page describes how to cancel Batch jobs.\nCancel jobs that you want to stop running or prevent from running.\n\nIdeally, you should configure your jobs to automatically stop running and\nfail whenever they don't behave as intended. For example, configure your\nrunnables to return a non-zero exit code or [timeout](/batch/docs/set-timeouts).\nBut, in practice, you might still want to manually stop unfinished\njobs. For example, cancel a job when you notice you need to troubleshoot or\nreplace a job that hasn't finished yet.\n\nLike succeeded and failed jobs, a cancelled job remains in your project for up\nto 60 days, after which Google Cloud automatically deletes the job. If you\nwant to cancel a job and don't need to retain the job's information, then you\ncan immediately [delete the job](/batch/docs/delete-job) instead.\n\nBefore you begin\n----------------\n\n1. If you haven't used Batch before, review [Get started with Batch](/batch/docs/get-started) and enable Batch by completing the [prerequisites for projects and users](/batch/docs/get-started#prerequisites).\n2.\n\n To get the permissions that\n you need to cancel a job,\n\n ask your administrator to grant you the\n\n\n [Batch Job Editor](/iam/docs/roles-permissions/batch#batch.jobsEditor) (`roles/batch.jobsEditor`)\n IAM role on the project.\n\n\n For more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\n You might also be able to get\n the required permissions through [custom\n roles](/iam/docs/creating-custom-roles) or other [predefined\n roles](/iam/docs/roles-overview#predefined).\n\n\u003cbr /\u003e\n\nCancel a job\n------------\n\nYou can cancel a job using the gcloud CLI or\nBatch API. \n\n### gcloud\n\nTo cancel a job using the gcloud CLI, use the\n[`gcloud batch jobs cancel` command](/sdk/gcloud/reference/batch/jobs/cancel): \n\n gcloud batch jobs cancel \u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e --location \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e: the name of the job.\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: the [location](/batch/docs/locations) of the job.\n\n### API\n\nTo cancel a job using the Batch API, use the\n[`jobs.cancel` method](/batch/docs/reference/rest/v1/projects.locations.jobs/cancel): \n\n POST https://batch.googleapis.com/v1/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e/jobs/\u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e:cancel\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the [project ID](/resource-manager/docs/creating-managing-projects#identifying_projects) of your project.\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: the [location](/batch/docs/locations) of the job.\n- \u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e: the name of the job.\n\nWhat's next\n-----------\n\n- Learn how to [limit run times using timeouts](/batch/docs/set-timeouts).\n- Learn about [troubleshooting](/batch/docs/troubleshooting).\n- Learn how to manage jobs:\n - [View the jobs in your project](/batch/docs/view-jobs-tasks).\n - [Export job information](/batch/docs/export-job-info).\n - [Delete jobs](/batch/docs/delete-job).\n- [Create another job](/batch/docs/create-run-job#job-creation-options)."]]