> 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/use-continuous-delivery/cd-building-blocks/services/propagate-and-override-cd-services.md).

# Propagate CD services

Use the same CD service across multiple pipeline stages, and override service configuration per environment.

You can reuse a CD stage service across multiple pipeline stages without duplicating its configuration. Once you add a stage with a service, you can select the same service in subsequent stages using the **Propagate from** option. You can also override service settings per environment to deploy the same service with different configurations at each stage.

***

## What you will learn from this topic

* How to [propagate a CD service](#propagate-a-service) from one stage to another in a pipeline.
* Understand [how propagation behaves](#propagate-services-through-multiple-stages) across multiple stages and stage templates.
* Understand the [limitations](#limitations) and [constraints](#service-propagation-behavior) of service propagation.
* How to [override service settings](#override-service-settings) per environment.

***

## Service propagation behavior

Review the following behavior and constraints before you propagate services.

![Propagate from option showing stage and service selection](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-40d53fae3e4ca5ce1d2070c6e54db5b4d1ee9f51%2Fb7df1f589cdc64982a5458c3ad1b107132e1b7e3634dfcfeb716c075437e1d6c.png?alt=media)

You can also use Harness [input sets and overlays](https://developer.harness.io/docs/platform/pipelines/input-sets) to select from different collections of settings at runtime.

The following constraints apply to service propagation:

* **Multiple services**: Service propagation is also supported when you use multiple services in a single stage (multi-service deployments). Go to [use multiple services and multiple environments in a deployment](/continuous-delivery/use-continuous-delivery/cd-building-blocks/advanced/multiserv-multienv.md) to configure multi-service deployments.
* **Forward propagation only**: Service propagation is progressive. You can only propagate services from stage to stage in a forward direction. For example, Stage 2 cannot propagate a service from a subsequent Stage 3.
* **Selective stage execution**: In a pipeline's **Advanced Options**, under **Stage Execution Settings**, you can set up selective stage executions to choose which stages to deploy at runtime. If you select a stage that uses a propagated service (a child service), that stage will not work. The parent service's settings must be resolved as part of the deployment. If the child service is overriding the parent service's settings, Harness cannot ensure that the settings are correctly overridden without deploying the parent service.
* **Stage reordering**: When propagation is set up between a parent stage and a child stage, moving either stage out of sequence resets any propagated settings to their defaults. You are prompted to confirm before the reset occurs.

  ![Prompt shown when reordering stages that use service propagation](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-6b27b89c7d109303755dcf16286b671781876bb8%2Fpropagate-and-override-cd-services-00.png?alt=media)
* **Shared input sets**: When you propagate a service from one stage to another, both stages must use the same input set. For example, if Stage 1 uses Input Set A and you propagate its service to Stage 2, Stage 2 must also use Input Set A. If Stage 2 uses a different input set, the service cannot propagate from Stage 1 to Stage 2.
* **Propagation chaining**: You cannot propagate a service from a stage that also propagates a service from another stage.
* **Artifact expressions**: Propagation copies service **configuration**, not resolved artifact versions. Artifact expressions such as `<+lastPublished.tag>` are re-evaluated in each stage and can resolve to different values.

***

## Propagate a service

Perform the following steps to propagate a service from one stage to another:

1. Open or create a pipeline with at least one stage. Go to [add a stage](https://developer.harness.io/docs/platform/pipelines/add-a-stage) to create your first stage.
2. To add another stage, select the plus sign (+) or select **Add Stage** after the first stage, then select **Deploy**.

   ![Add stage dialog showing the Deploy option](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-61fafb578ca89fe0c11e9fd92d1b2f9f0538388e%2Fpropagate-and-override-cd-services-01.png?alt=media)
3. Enter a stage name and select **Set Up Stage**. The new stage is added to the pipeline.
4. Select the **Service** tab if it is not already selected. The propagation option appears.

   ![Service tab showing the Propagate from option](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-89e62eedf3fec8cceb59aebe3a44ef77a11b69a9%2Fpropagate-and-override-cd-services-02.png?alt=media)
5. Select **Propagate from**, then select the stage with the service you want to use.

   ![Propagate from dropdown showing stage and service name](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-83eb09c713e3fc2233dcd435c4b060d17b559326%2Fpropagate-and-override-cd-services-03.png?alt=media)

The stage uses the same service as the stage you selected.

***

## Propagate services through multiple stages

When defining a pipeline, you can pass the service, its variables, artifact, and manifest inputs through multiple stages. You can propagate a service from a previous templated or non-templated stage, and from one templated stage to another stage that refers to a different template.

### Limitations

You cannot propagate services between different deployment types. For example, you cannot propagate a Kubernetes service between a Kubernetes deployment stage and a Native Helm deployment stage.

### Requirements

Configure the service as a runtime input in the stage template or stage before you propagate it.

### Propagate services from one stage template to another

Perform the following steps to propagate a service between stage templates:

1. Open or create a pipeline with two stage templates. Go to [create a stage template](/continuous-delivery/use-continuous-delivery/cd-building-blocks/templates/create-a-remote-stage-template.md) to set up templates.
2. Select the **Service** tab if it is not already selected. The propagation option appears.

   ![Service tab showing Propagate from in a template stage](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-90e47fdaa71ac72f8a9f3390fc09c95962883125%2Ftemplate-stage-propagation1.png?alt=media)
3. Select **Propagate from**, then select the stage with the service you want to use.

   ![Propagate from selection showing stage name and service name in template stage](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-2d9906393be252d33e8a2e4706941ad07b9b098c%2Ftemplate-stage-propagation2.png?alt=media)

You can also propagate a service from one template stage to another if the service is configured as a runtime input.

The following example shows a service propagation YAML configuration with three stages: one source stage and two stages that propagate from it.

{% code title="service-propagation.yaml" %}

```yaml
pipeline:
  name: Deployment Pipeline
  identifier: Deployment_Pipeline
  projectIdentifier: <PROJECT_ID>
  orgIdentifier: default
  tags: {}
  stages:
    - stage:
        name: Deploy Dev
        identifier: Deploy_Dev
        template:
          templateRef: Deploy_Stage_1
          versionLabel: "1.01"
          templateInputs:
            type: Deployment
            spec:
              service:
                serviceInputs:
                  serviceDefinition:
                    type: Kubernetes
                    spec:
                      artifacts:
                        primary:
                          primaryArtifactRef: nginx
                          sources:
                            - identifier: nginx
                              type: DockerRegistry
                              spec:
                                tag: <+input>
                serviceRef: nginxcanary
    - stage:
        name: Deploy to QA
        identifier: Deploy_to_QA
        template:
          templateRef: Deploy_Stage_1
          versionLabel: "1.01"
          templateInputs:
            type: Deployment
            spec:
              service:
                useFromStage:
                  stage: Deploy_Dev
    - stage:
        name: Deploy to Prod
        identifier: Deploy_to_Prod
        template:
          templateRef: Deploy_Stage_1
          versionLabel: "1.01"
          templateInputs:
            type: Deployment
            spec:
              service:
                useFromStage:
                  stage: Deploy_Dev
```

{% endcode %}

### Service propagation walkthrough <a href="#video-walkthrough" id="video-walkthrough"></a>

The following video demonstrates how to propagate a service across stage templates.

{% embed url="<https://www.loom.com/share/79b0d4c9c4634d2e95da1a832ef8060f>" %}

***

## Multiple service deployments

A multiple service deployment deploys multiple services in the same stage. Go to [use multiple services and multiple environments in a deployment](/continuous-delivery/use-continuous-delivery/cd-building-blocks/advanced/multiserv-multienv.md) to configure multiple service deployments.

***

## Override service settings

You can override a service's settings using **Environment Overrides** or by overlaying values YAML files.

Go to [overriding service settings in environments](/continuous-delivery/use-continuous-delivery/cd-building-blocks/environments/create-environments.md) to configure environment overrides. The following information covers overriding services in services and environments v1 only.

A common method for overriding values YAML files is to use the `<+env.name>` Harness expression in the **File Path** of the `values.yaml` file, then name your Harness environments to match your values YAML file names.

![Values YAML file path configuration using the env.name expression](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-1ae6d6194b7dcd05654a44d376a6356e94150bcd%2F6cffc4e7fc1159c37eece2bb6cc2a7e76a115652155fe93c91a3f80a68328112.png?alt=media)

You can also override the `values.yaml` files without using environments. To overlay values files in Harness, add multiple files or replace file paths dynamically at runtime.

![Overlay values YAML files configuration](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-4d645ac580f6c8b4357fb329c3267b8565785ee4%2F0bbc97758875d869b84bcf9ee6648103f217ecd0923076a0f2d86f3c821e0df7.png?alt=media)

Go to [add and override values YAML files](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-kubernetes-category/add-and-override-values-yaml-files.md) to layer or replace values YAML files.

***

## Next steps

Use service propagation and overrides to configure multi-stage deployments and environment-specific settings.

* [Use multiple services and multiple environments in a deployment](/continuous-delivery/use-continuous-delivery/cd-building-blocks/advanced/multiserv-multienv.md): Configure deployments that span multiple services and environments.
* [Overriding service settings in environments](/continuous-delivery/use-continuous-delivery/cd-building-blocks/environments/create-environments.md): Override service settings at the environment level.
* [Add and override values YAML files](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-kubernetes-category/add-and-override-values-yaml-files.md): Layer or replace values YAML files for Kubernetes deployments.
* [Add a stage](https://developer.harness.io/docs/platform/pipelines/add-a-stage): Configure additional pipeline stages for CD deployments.
