Stay organized with collections
Save and categorize content based on your preferences.
This document describes how to create and run a job that isn't scheduled
until specific jobs have succeeded or failed. To learn more about job states,
see Job creation and execution overview.
If you have a workload with varying resource requirements, consider using
dependent jobs to create an automated chain of jobs that each use separate VMs.
For example, separate the types of VMs used for low-demand operations
(like data preparation) and compute-intensive operations (like data processing).
By using dependent jobs to help optimize resource consumption, you can reduce
costs and quota usage.
A dependent job can have up to four dependencies. Each dependency must contain
a unique job name and one of the following required states:
SUCCEEDED: succeeded
FAILED: failed
FINISHED: succeeded or failed
When you create a dependent job, all of its dependency jobs must exist.
A dependent job can't enter the scheduled (SCHEDULED) state until each
dependency job has entered its required state. If it becomes impossible for a
dependency job to enter its required state, then the dependent job immediately
fails without being scheduled.
Like all jobs, a dependent job can't enter the scheduled (SCHEDULED) state
if the job exceeds the
maximum wait time in the queue.
Batch enforces this limit to prevent your jobs from becoming
stale. Consequently, if you expect the remaining time required for any of the
dependency jobs to finish might exceed this limit, then consider doing one
or more of the following:
If you haven't created a dependency job yet, try to reduce the expected run
time of the dependency job. For example, you might increase the parallelism
of the workload or limit the run time of any
tasks and runnables that you don't need to succeed.
Wait to create the dependent job until the expected run time of the
dependency jobs is lower than the limit.
Create a dependent job
You can create a job that
is dependent using the following methods:
To specify that a job is dependent, include the
dependencies[].items field,
which supports one or more dependencies specified as key-value pairs, in the
main body in the JSON file:
DEPENDENCY_JOB_NAME: the name of a dependency job,
which must reach its required state before this dependent job is allowed to
be scheduled.
REQUIRED_STATE: the required state for the
corresponding dependency job, which must be SUCCEEDED, FAILED, or
FINISHED.
For example, a dependent job with three dependencies can have a JSON
configuration file that is similar to the following:
{"taskGroups":[{"taskSpec":{"runnables":[{"script":{"text":"echo Hello World! This is task $BATCH_TASK_INDEX."}}]},"taskCount":3}],"dependencies":[{"items":{"DEPENDENCY_JOB_NAME_1":"REQUIRED_STATE_1","DEPENDENCY_JOB_NAME_2":"REQUIRED_STATE_2","DEPENDENCY_JOB_NAME_3":"REQUIRED_STATE_3"}}]}
What's next
If you have issues creating or running a job, see
Troubleshooting.
[[["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 document explains how to create dependent jobs, which are jobs that begin only after specific prior jobs have either succeeded, failed, or finished.\u003c/p\u003e\n"],["\u003cp\u003eUsing dependent jobs helps optimize resource allocation by allowing different VM types to be used for different job phases, such as data preparation versus data processing.\u003c/p\u003e\n"],["\u003cp\u003eDependent jobs have restrictions, such as a maximum of four dependencies, and the required states for dependencies can be \u003ccode\u003eSUCCEEDED\u003c/code\u003e, \u003ccode\u003eFAILED\u003c/code\u003e, or \u003ccode\u003eFINISHED\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eWhen creating a dependent job, all dependency jobs must already exist, and the dependent job won't schedule until each dependency reaches its designated state.\u003c/p\u003e\n"],["\u003cp\u003eYou can create a dependent job using the Google Cloud CLI's \u003ccode\u003egcloud alpha batch jobs submit\u003c/code\u003e command or the Batch API's \u003ccode\u003ev1alpha jobs.create\u003c/code\u003e method, specifying dependencies in the \u003ccode\u003edependencies[].items\u003c/code\u003e field.\u003c/p\u003e\n"]]],[],null,["# Schedule dependent jobs\n\nThis document describes how to create and run a job that isn't scheduled\nuntil specific jobs have succeeded or failed. To learn more about job states,\nsee [Job creation and execution overview](/batch/docs/create-run-job).\n\nIf you have a workload with varying resource requirements, consider using\ndependent jobs to create an automated chain of jobs that each use separate VMs.\nFor example, separate the types of VMs used for low-demand operations\n(like data preparation) and compute-intensive operations (like data processing).\nBy using dependent jobs to help optimize resource consumption, you can reduce\ncosts and quota usage.\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 create a job,\n\n ask your administrator to grant you the\n following IAM roles:\n\n - [Batch Job Editor](/iam/docs/roles-permissions/batch#batch.jobsEditor) (`roles/batch.jobsEditor`) on the project\n - [Service Account User](/iam/docs/roles-permissions/iam#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the [job's service account](/batch/docs/create-run-job-custom-service-account#create-job-service-account), which by default is the [default Compute Engine service account](/compute/docs/access/service-accounts#default_service_account)\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\n### Restrictions\n\nDependent jobs have the following restrictions:\n\n- A dependent job can have up to four dependencies. Each dependency must contain\n a unique job name and one of the following required states:\n\n - `SUCCEEDED`: succeeded\n - `FAILED`: failed\n - `FINISHED`: succeeded or failed\n- When you create a dependent job, all of its dependency jobs must exist.\n\n- A dependent job can't enter the scheduled (`SCHEDULED`) state until each\n dependency job has entered its required state. If it becomes impossible for a\n dependency job to enter its required state, then the dependent job immediately\n fails without being scheduled.\n\n | **Note:** You don't need to wait to delete finished dependency jobs. A dependent job automatically remembers if a deleted dependency job reached its required state.\n- Like all jobs, a dependent job can't enter the scheduled (`SCHEDULED`) state\n if the job exceeds the\n [maximum wait time in the queue](/batch/quotas#max-job-queue).\n Batch enforces this limit to prevent your jobs from becoming\n stale. Consequently, if you expect the remaining time required for any of the\n dependency jobs to finish might exceed this limit, then consider doing one\n or more of the following:\n\n - If you haven't created a dependency job yet, try to reduce the expected run time of the dependency job. For example, you might increase the parallelism of the workload or [limit the run time](/batch/docs/set-timeouts) of any tasks and runnables that you don't need to succeed.\n - Wait to create the dependent job until the expected run time of the dependency jobs is lower than the limit.\n\n### Create a dependent job\n\nYou can [create a job](/batch/docs/create-run-basic-job#create-basic-job) that\nis dependent using the following methods:\n\n- For the Google Cloud CLI, use the [`gcloud alpha batch jobs submit` command](/sdk/gcloud/reference/alpha/batch/jobs/submit).\n- For the Batch API, use the [v1alpha `jobs.create` method](/batch/docs/reference/rest/v1alpha/projects.locations.jobs/create).\n\nTo specify that a job is dependent, include the\n[`dependencies[].items` field](/batch/docs/reference/rest/v1alpha/projects.locations.jobs#Job.FIELDS.dependencies),\nwhich supports one or more dependencies specified as key-value pairs, in the\nmain body in the JSON file: \n\n \"dependencies\": [\n {\n \"items\": {\n \"\u003cvar translate=\"no\"\u003eDEPENDENCY_JOB_NAME\u003c/var\u003e\": \"\u003cvar translate=\"no\"\u003eREQUIRED_STATE\u003c/var\u003e\"\n }\n }\n ]\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eDEPENDENCY_JOB_NAME\u003c/var\u003e: the name of a dependency job,\n which must reach its required state before this dependent job is allowed to\n be scheduled.\n\n- \u003cvar translate=\"no\"\u003eREQUIRED_STATE\u003c/var\u003e: the required state for the\n corresponding dependency job, which must be `SUCCEEDED`, `FAILED`, or\n `FINISHED`.\n\nFor example, a dependent job with three dependencies can have a JSON\nconfiguration file that is similar to the following: \n\n {\n \"taskGroups\": [\n {\n \"taskSpec\": {\n \"runnables\": [\n {\n \"script\": {\n \"text\": \"echo Hello World! This is task $BATCH_TASK_INDEX.\"\n }\n }\n ]\n },\n \"taskCount\": 3\n }\n ],\n \"dependencies\": [\n {\n \"items\": {\n \"\u003cvar translate=\"no\"\u003eDEPENDENCY_JOB_NAME_1\u003c/var\u003e\": \"\u003cvar translate=\"no\"\u003eREQUIRED_STATE_1\u003c/var\u003e\",\n \"\u003cvar translate=\"no\"\u003eDEPENDENCY_JOB_NAME_2\u003c/var\u003e\": \"\u003cvar translate=\"no\"\u003eREQUIRED_STATE_2\u003c/var\u003e\",\n \"\u003cvar translate=\"no\"\u003eDEPENDENCY_JOB_NAME_3\u003c/var\u003e\": \"\u003cvar translate=\"no\"\u003eREQUIRED_STATE_3\u003c/var\u003e\"\n }\n }\n ]\n }\n\nWhat's next\n-----------\n\n- If you have issues creating or running a job, see [Troubleshooting](/batch/docs/troubleshooting).\n- Learn how to [view jobs and tasks](/batch/docs/view-jobs-tasks).\n- Learn about more [job creation options](/batch/docs/create-run-job#job-creation-options)."]]