> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/3.0/use-deployments/overview-3/gcr-deploy/gcr-job.md).

# Google Cloud Run Job

Deploy and execute a Cloud Run Job using the Google Cloud Run Job step.

The Google Cloud Run Job step deploys or updates a Cloud Run Job definition and executes it. Use this step for batch workloads, scheduled tasks, and background processing that run to completion rather than serving ongoing requests.

***

## Step YAML

Execute an existing job by name (execute only):

```yaml
- name: Google Cloud Run Job
  id: googleCloudRunJobStep
  template:
    uses: googleCloudRunJobStep
    with:
      job_name: my-batch-job
      execute_command_options: "--update-env-vars=ENV=production"
```

Replace the job definition from the service manifest, then execute (Job Name empty):

```yaml
- name: Google Cloud Run Job
  id: googleCloudRunJobStep
  template:
    uses: googleCloudRunJobStep
    with:
      replace_command_options: "--async --verbosity=debug"
      execute_command_options: "--update-env-vars=key1=value1,key2=value2"
```

***

## Before you begin

* **A Google Cloud Run infrastructure** with a GCP connector and region. Go to [Google Cloud Run infrastructure](/continuous-delivery/3.0/use-deployments/overview-3/google-cloud-run-infrastructure.md).
* **A Cloud Run Job manifest** (optional). Required only when you want to update the job definition before executing. If you only want to execute an existing job, only the job name is needed.
* Add this step using the **blank canvas** deployment strategy. Go to [Blank canvas](/continuous-delivery/3.0/use-deployments/overview-3/basic/blank-canvas.md).

***

## Configure the step

The step operates in one of two modes based on whether **Job Name** is set. Infrastructure fields are resolved from the stage context when not set explicitly.

### Job configuration

| Field                       | Description                                                                                                                                                                                          |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Job Name**                | The name of the Cloud Run job to execute. When set, the step runs execute only (`gcloud run jobs execute`). Leave empty to replace the job definition from the service manifest first, then execute. |
| **Replace Command Options** | Additional flags passed to `gcloud run jobs replace` (for example, `--async --verbosity=debug`). Only applies when **Job Name** is empty. Does not trigger replace on its own.                       |
| **Execute Command Options** | Additional flags passed to `gcloud run jobs execute` (for example, `--update-env-vars=key1=value1`).                                                                                                 |

### Infrastructure configuration

GCP Connector, GCP Region, and GCP Project are available under **+ More options** on the step. When not set, Harness resolves these from the infrastructure definition.

| Field             | Default value            | Description                             |
| ----------------- | ------------------------ | --------------------------------------- |
| **GCP Connector** | Infrastructure connector | The GCP connector used to authenticate. |
| **GCP Region**    | `${{infra.region}}`      | The GCP region of the Cloud Run job.    |
| **GCP Project**   | `${{infra.project}}`     | The GCP project.                        |

***

## Advanced settings

* **Timeout duration:** Maximum time the step is allowed to run before being terminated.
* **On failure:** Define what happens if the step fails: retry, mark as success, or abort.
* **Strategy:** Configure a looping strategy to run this step over a list of values.
* **Conditional execution:** Run this step only when a specified condition is true.

***

## How it runs

When the Job step executes, the following sequence occurs:

1. Authenticates with GCP using the configured connector. For Service Account auth (ManualConfig), runs `gcloud auth activate-service-account --key-file sa_key.json`. For Inherit from Delegate, identifies the active account via `gcloud auth list`.
2. Configures the gcloud environment: sets project and region.
3. Determines the mode based on **Job Name**:
   * **Job Name empty:** runs `gcloud run jobs replace <manifest>` to create or update the job definition from the service manifest. Any flags from **Replace Command Options** are appended.
   * **Job Name set:** skips replace.
4. Runs `gcloud run jobs execute <job-name>` to trigger the job execution. Any flags from **Execute Command Options** are appended to this command.

***

## Next steps

* Go to [Blank canvas](/continuous-delivery/3.0/use-deployments/overview-3/basic/blank-canvas.md) to set up a stage for Cloud Run Job deployments.
* Go to [Google Cloud Run Deploy](/continuous-delivery/3.0/use-deployments/overview-3/gcr-deploy.md) for service deployments that use `gcloud run services replace` instead.

{% @harness-feedback/feedback %}
