> 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.md).

# Step Library

Apply a Cloud Run service manifest and create a new revision using the Google Cloud Run Deploy step.

The Google Cloud Run Deploy step applies your service manifest to Cloud Run, creates a new revision, and optionally shifts all traffic to it immediately. The step also saves rollback data so Harness can restore the previous revision if the stage fails.

***

## Step YAML

```yaml
- name: Google Cloud Run Deploy
  id: googleCloudRunDeployStep
  template:
    uses: googleCloudRunDeployStep
```

The step uses no explicit `with:` inputs by default; service configuration and infrastructure are resolved from the stage context at runtime.

With explicit overrides:

```yaml
- name: Google Cloud Run Deploy
  id: googleCloudRunDeployStep
  template:
    uses: googleCloudRunDeployStep
    with:
      skip_traffic_update: true
      cmd_options: "--port=8080"
      cmd_timeout: 15m
      log_level: debug
```

***

## Before you begin

* **A Google Cloud Run service** with a service manifest and artifact source. Go to [Google Cloud Run services](/continuous-delivery/3.0/use-deployments/overview-3/google-cloud-run-services.md).
* **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).

***

## Configure the step

The following fields appear on the Deploy step. Most values are resolved automatically from the service and infrastructure definition; add a `with:` block only when you need to override a specific field.

### Service configuration

| Field                       | Default value               | Description                                                                                            |
| --------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------ |
| **Service Manifest Path**   | `${{runtime.manifestPath}}` | Path to the downloaded service manifest. Resolved automatically at runtime.                            |
| **Service Container Image** | `${{artifact.image}}`       | Container image URL from the artifact source. Harness injects this into the manifest before deploying. |

### Infrastructure configuration

| Field             | Default value            | Description                                                                                         |
| ----------------- | ------------------------ | --------------------------------------------------------------------------------------------------- |
| **GCP Connector** | Infrastructure connector | The GCP connector used to authenticate. Defaults to the connector in the infrastructure definition. |
| **GCP Region**    | `${{infra.region}}`      | The Cloud Run service region. Resolved from the infrastructure definition.                          |
| **GCP Project**   | `${{infra.project}}`     | The GCP project. Resolved from the infrastructure definition.                                       |

### Deployment options

| Field                   | Default value | Description                                                                                                                                        |
| ----------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Command Options**     | —             | Additional flags passed to `gcloud run services replace` (for example, `--port=8080`).                                                             |
| **Skip Traffic Update** | `false`       | When `true`, creates a new revision without shifting any traffic. Use with a Traffic Shift step to control when traffic moves to the new revision. |
| **Command Timeout**     | `10m`         | Maximum time the step is allowed to run.                                                                                                           |
| **Log Level**           | `info`        | Log verbosity for the step.                                                                                                                        |

{% hint style="info" %}
**Skip Traffic Update on first deployment**

Skip Traffic Update applies to subsequent deployments only. On the first deployment of a service, Harness always shifts traffic to the new revision regardless of this setting.
{% endhint %}

***

## Step outputs

After the step completes, the following values are saved to rollback data and are accessible via `${{rollback.data.<key>}}` in the Rollback step.

| Output key            | Rollback expression                    | Description                                                                                                                                          |
| --------------------- | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SERVICE`             | `${{rollback.data.SERVICE}}`           | The Cloud Run service name.                                                                                                                          |
| `REVISION_METADATA`   | `${{rollback.data.REVISION_METADATA}}` | The post-deploy revision name and traffic state, saved as a JSON string. The Rollback step reads this to identify the revision to restore.           |
| `FIRST_DEPLOYMENT`    | `${{rollback.data.FIRST_DEPLOYMENT}}`  | Whether this was the first deployment of the service. Harness uses this internally to decide between traffic restore and service delete on rollback. |
| `INSTANCES`           | —                                      | Instance count reported by Google Cloud Monitoring after the deployment.                                                                             |
| `DEPLOYMENT_METADATA` | —                                      | Full deployment metadata for Harness instance tracking.                                                                                              |

***

## 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 Deploy 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:

   ```
   gcloud config set project <project>
   gcloud config set compute/region <region>
   gcloud config set run/region <region>
   ```
3. Extracts the service name from the manifest and saves it to step output as `SERVICE`.
4. Injects the container image URL from the artifact source into the manifest at `/harness/manifest/GoogleCloudRun/ServiceManifest.yaml`.
5. Applies the manifest: `gcloud run services replace /harness/manifest/GoogleCloudRun/ServiceManifest.yaml`. Cloud Run creates a new revision and, unless **Skip Traffic Update** is enabled, routes all traffic to it immediately.
6. Runs `gcloud run services describe <service> --format json` to capture the resulting revision name and traffic state.
7. Saves the revision name and traffic distribution as `REVISION_METADATA` to step output. For example:

   ```json
   {"status":{"traffic":[{"percent":100,"revisionName":"my-svc-00004-xyz"}],"latestCreatedRevisionName":"my-svc-00004-xyz"}}
   ```
8. Performs instance sync using the Google Cloud Monitoring SDK with filter:

   ```
   metric.type="run.googleapis.com/container/instance_count" AND resource.label.service_name="<service>"
   ```

   If no data is available, retries every 60 seconds, up to 10 times. If data is found, waits an additional 60 seconds for a stable read. Factor up to 10 minutes of instance sync into your expected step duration.
9. Publishes `INSTANCES` and `DEPLOYMENT_METADATA` to step output.

***

## Next steps

* Go to [Google Cloud Run Traffic Shift](/continuous-delivery/3.0/use-deployments/overview-3/gcr-deploy/gcr-traffic-shift.md) to route traffic to a specific revision after deploy.
* Go to [Google Cloud Run Rollback](/continuous-delivery/3.0/use-deployments/overview-3/gcr-deploy/gcr-rollback.md) for the rollback step that restores the previous revision.
* Go to [Canary deployment](/continuous-delivery/3.0/use-deployments/overview-3/basic/canary.md) for a full walkthrough of the Deploy and Traffic Shift steps together.

{% @harness-feedback/feedback %}
