This page contains code samples for Batch. To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.
Create and submit a basic container job
Create and submit a sample Batch job that runs a simple command specified as a container image. After you submit the job, Batch automatically queues, schedules, and executes the job on Compute Engine VMs.
View in documentation
Create and submit a basic script job
Create and submit a sample Batch job that runs a simple command specified as a script. After you submit the job, Batch automatically queues, schedules, and executes the job on Compute Engine VMs.
View in documentation
Create and submit a job that uses a Cloud Storage bucket
Create and submit a sample Batch job that runs a script that accesses an existing Cloud Storage bucket. The job's definition specifies to mount the bucket to all VMs so that the job's tasks can read input data from it or write results to it. After you submit the job, Batch automatically queues, schedules, and executes the job on Compute Engine VMs.
View in documentation
Create and submit a job using a VM instance template
Create and submit a sample Batch job that runs a script and specifies an existing instance template to define its VM requirements. After you submit the job, Batch automatically queues, schedules, and executes the job on Compute Engine VMs that match the instance template that you specified.
View in documentation
View in documentation
View in documentation
Describe a task
A Batch job consists of one or several tasks. This sample retrieves the name and detailed status info for a given task.
View in documentation
List jobs
List your Batch jobs from a specific location. Note: a job's location might differ from where that job runs.
View in documentation
List tasks
A Batch job consists of one or several tasks. This sample retrieves the name and current state of all tasks in a given job.
View in documentation
View logs from Cloud Logging for a job
If the job has been set up to write logs to Cloud Logging, this sample retrieves its logs. Logs can provide information that is useful for analyzing your jobs. For example, logs can help you debug a failed job.
View in documentation