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—for example, by configuring your runnables to return a non-zero exit code or timeout—whenever they don't behave as intended. 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.
Before you begin
- If you haven't used Batch before, review Get started with Batch and enable Batch by completing the prerequisites for projects and users.
-
To get the permissions that you need to cancel a job, ask your administrator to grant you the Batch Job Editor (
roles/batch.jobsEditor
) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.You might also be able to get the required permissions through custom roles or other predefined roles.
Cancel a job
You can cancel a job using the Google Cloud CLI or Batch API.
gcloud
To cancel a job using the gcloud CLI, use the
gcloud alpha batch jobs cancel
command:
gcloud alpha batch jobs cancel JOB_NAME --location LOCATION
Replace the following:
JOB_NAME
: the name of the job.LOCATION
: the location of the job.
API
To cancel a job using the Batch API, use the
jobs.cancel
v1alpha method:
POST https://batch.googleapis.com/v1alpha/projects/PROJECT_ID/locations/LOCATION/jobs/JOB_NAME:cancel
Replace the following:
PROJECT_ID
: the project ID of your project.LOCATION
: the location of the job.JOB_NAME
: the name of the job.
What's next
- Learn how to limit run times using timeouts.
- Learn about troubleshooting.
- Learn how to manage jobs:
- Create another job.