> 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/harness-platform/use-harness-platform/pipelines/run-specific-stage-in-pipeline.md).

# Run specific stages

A pipeline can contain multiple stages that perform different parts of a workflow. Selective stage execution lets you run specific stages instead of running the entire pipeline.

For example, if you need to rerun a stage without running the other stages, you can select that stage when starting a pipeline execution.

***

### What you will learn from this topic <a href="#what-you-will-learn-from-this-topic" id="what-you-will-learn-from-this-topic"></a>

* Understand [dependent and independent stages](#dependent-and-independent-stages).
* How to [enable selective stage execution](#enable-selective-stage-executions) for a pipeline.
* How to [run specific stages](#run-specific-stages) when executing a pipeline.
* How to [rerun stages from execution history](#rerun-stages-from-execution-history) after a pipeline run completes.

***

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

* **Harness project**: You need an existing project. For more information, refer to [Organizations and Projects](https://github.com/iKettles/harness-gitbook/tree/main/docs/platform/organizations-and-projects/projects-and-organizations/README.md).
* **Pipeline with stages**: You need a pipeline with multiple stages. For more information, refer to [Add a stage](/harness-platform/use-harness-platform/pipelines/add-a-stage.md).
* **Pipeline permissions**: You need **Pipeline: Execute** permission to run pipelines. For more information, refer to [RBAC in Harness](/harness-platform/3.0/harness-platform-resources/platform-access-control/rbac-in-harness.md).
* **Key concepts**: Familiarity with [Harness key concepts](/service-reliability-management/new-to-srm/get-started/key-concepts.md) is helpful but not required.

***

### Dependent and independent stages <a href="#dependent-and-independent-stages" id="dependent-and-independent-stages"></a>

Stage dependencies determine which stages you can select to run when using selective stage execution. Harness distinguishes between dependent and independent stages based on whether a stage requires input or context from another stage.

#### Independent stages <a href="#independent-stages" id="independent-stages"></a>

An independent stage is a stage that does not use settings from any other stage. Independent stages can execute without requiring input or context from another stage.

When you select an independent stage to run, you can run it individually without running other stages in the pipeline.

#### Dependent stages <a href="#dependent-stages" id="dependent-stages"></a>

A dependent stage is a stage that uses another stage's settings. Stages can be dependent on input from previous stages in the following ways:

* **Infrastructure settings**: A stage can inherit infrastructure settings from a previous stage.
* **Services and Environments**: Some settings can be propagated from one stage to another, such as [Services](/continuous-delivery/use-continuous-delivery/cd-building-blocks/services/services-overview.md) and [Environments](/continuous-delivery/use-continuous-delivery/cd-building-blocks/environments/environment-overview.md).
* **Expressions**: You can use [expressions](/harness-platform/use-harness-platform/variables-and-expressions/runtime-inputs.md) to reference stage settings, such as stage variables, step inputs, and step outputs across stages.

To run a dependent stage, you must either:

* Provide the dependencies as runtime inputs when you run the stage.
* Run the dependent stage and all the stages it depends on.

When you select a dependent stage to run, Harness automatically selects all upstream stages that the selected stage depends on. You cannot deselect these upstream stages because they are required for the dependent stage to execute.

***

### Enable selective stage executions <a href="#enable-selective-stage-executions" id="enable-selective-stage-executions"></a>

Before you can run specific stages, you must enable selective stage execution in your pipeline settings.

Perform the following steps to enable selective stage execution.

1. In Harness, open your pipeline in Pipeline Studio.
2. In the Pipeline Studio Visual Editor, select **Advanced Options**.
3. In the **Stage Execution Settings** section, select **Yes** for **Allow selective stage(s) executions**.

   <figure><img src="/files/1RUyFi2P0GgOn8uMobph" alt="Stage Execution Settings showing Allow selective stage(s) executions option"><figcaption></figcaption></figure>
4. Select **Save** to save the pipeline.

<details>

<summary>YAML example</summary>

```yaml
pipeline:
  name: My Pipeline
  identifier: My_Pipeline
  allowStageExecutions: true  # Enable selective stage execution
  stages:
    - stage:
        name: Build
        identifier: Build
        type: CI
        spec:
          # ... stage configuration ...
    - stage:
        name: Deploy
        identifier: Deploy
        type: Deployment
        spec:
          # ... stage configuration ...
```

</details>

***

### Run specific stages <a href="#run-specific-stages" id="run-specific-stages"></a>

After enabling selective stage execution, you can choose which stages to run when you execute the pipeline.

Consider the following when selecting stages:

* Select stages that have all required inputs and dependencies available.
* A stage that depends on settings from another stage might require the dependent stages to be included in the execution.
* Selective stage execution determines which stages are included in the pipeline execution. It does not change the configuration of the stages.

Perform the following steps to run specific stages in a pipeline.

1. In Harness, navigate to your pipeline and select **Run**.
2. In the **Run Pipeline** dialog, select the **Stages** tab.
3. Select the independent stages you want to run. Harness automatically selects dependent stages and their upstream dependencies.

   <figure><img src="/files/jCKDjUNWBqk6xxhLAx0t" alt="Stage selection in the Run Pipeline dialog showing available stages"><figcaption></figcaption></figure>
4. If the selected stages require runtime inputs, provide the required values.

   <figure><img src="/files/2QVWhRYIrjSqJSjs8UnK" alt="Runtime inputs tab in the Run Pipeline dialog"><figcaption></figcaption></figure>
5. Select **Run Pipeline**.

The pipeline executes only the selected stages and their dependencies. Stages that are not selected are skipped. You can view the execution details in the pipeline execution history.

***

### Rerun stages from execution history <a href="#rerun-stages-from-execution-history" id="rerun-stages-from-execution-history"></a>

After a pipeline run completes, you can rerun a single stage from the execution history without rerunning the entire pipeline.

Perform the following steps to rerun a stage from execution history.

1. In Harness, navigate to your pipeline and select the **Execution History** tab.
2. Select the execution you want to rerun from.
3. In the execution details view, select **Re-run Stage** on the stage card you want to rerun.

   <figure><img src="/files/2spw6CP2Yvv0uVuzFkmb" alt="Re-run Stage button on a stage card in execution history"><figcaption></figcaption></figure>
4. If the stage requires runtime inputs, provide the required values in the **Re-run Stage** dialog.
5. Select **Re-run Stage** to start the execution.

You can rerun a stage from execution history even when the pipeline execution was successful. For more information on viewing execution history, go to [Execution history and logs](https://github.com/iKettles/harness-gitbook/tree/main/docs/category/execution-history-and-logs/README.md).

***

### Selective stage execution and triggers <a href="#selective-stage-execution-and-triggers" id="selective-stage-execution-and-triggers"></a>

Selective stage execution can also be used with supported triggers to run specific stages.

For information about configuring a trigger to execute specific stages, go to [Selective pipeline stage execution by using triggers](/harness-platform/use-harness-platform/triggers/selective-stage-execution-using-triggers.md).

***

### Next steps <a href="#next-steps" id="next-steps"></a>

* [Add a stage](/harness-platform/use-harness-platform/pipelines/add-a-stage.md): Learn how to add and configure stages in your pipeline.
* [Runtime inputs](/harness-platform/use-harness-platform/variables-and-expressions/runtime-inputs.md): Provide values at execution time instead of defining them in the pipeline.
* [Execution history and logs](https://github.com/iKettles/harness-gitbook/tree/main/docs/category/execution-history-and-logs/README.md): View and analyze pipeline execution history and logs.
