> 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/cd-steps/flow-control/control-resource-usage-with-queue-steps.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# Control resource usage with Queue steps

Control the order in which pipelines access the same deployment resources

Use the **Queue** step to control the order in which pipelines access the resources Harness requests during a deployment, and to prevent multiple pipelines from requesting the same resources at the same time.

For example, two pipelines might deploy artifacts to a single Kubernetes namespace at the same time. To avoid a collision and queue the deployments, add a Queue step to each pipeline.

When the first pipeline completes, it releases the lock and the second pipeline can continue.

Queue steps can be used on different pipelines or on multiple executions of the same pipeline.

Harness provides multiple options for controlling resource usage and protecting capacity limits. For more information, go to [Controlling resource usage with Barriers, Resource Constraints, and Queue steps](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/flow-control/controlling-deployments-with-barriers-resource-constraints-and-queue-steps.md).

***

## What you will learn from this topic

* How to [add a Queue step](#add-queue-steps) and set the resource key shared by the pipelines that must wait
* How to choose whether the next execution waits for the [pipeline or the stage](#add-queue-steps) to finish
* How to [review an example](#test) that queues a second run until the first run completes

***

## Before you begin

Add the Queue step in a stage **Execution** sequence.

* **Sample pipeline**: The example uses a Custom stage. Update `projectIdentifier` and `orgIdentifier` in the sample to match your project and organization. Go to [Organizations and projects](https://developer.harness.io/harness-platform/use-harness-platform/organizations-and-projects) to find those identifiers.

***

## Add a Queue step <a href="#add-queue-steps" id="add-queue-steps"></a>

Perform the following steps to add a Queue step:

1. In the stage, select **Execution**.
2. Select **Add Step** at the point where deployments should wait.
3. Select **Flow Control**.
4. Select **Queue**.
5. Enter a name for the Queue step.
6. Enter a timeout for the Queue step.
7. In **Resource Key**, enter a unique key. Use this same key on the Queue steps in the other pipelines.
8. In **Run next queued execution after completion of**, select one of the following:
   * **Pipeline**: The entire pipeline must complete before the queued pipelines can deploy.
   * **Stage**: The current stage must complete before the queued pipelines can deploy.

**Resource Key** supports **Fixed Values**, **Runtime Inputs**, and **Expressions**. For more information, go to [Fixed values, runtime inputs, and expressions](https://developer.harness.io/harness-platform/use-harness-platform/variables-and-expressions/runtime-inputs).

Queue steps can be used on different pipelines or on multiple executions of the same pipeline.

### Advanced settings <a href="#advanced-settings" id="advanced-settings"></a>

In **Advanced**, you can use the following options:

* [Delegate selectors](https://developer.harness.io/harness-platform/use-harness-platform/delegates/delegate/manage-delegates/select-delegates-with-selectors)
* [Conditional execution](https://developer.harness.io/harness-platform/use-harness-platform/pipelines/step-skip-condition-settings)
* [Failure strategy](https://developer.harness.io/harness-platform/use-harness-platform/pipelines/failure-handling/define-a-failure-strategy-on-stages-and-steps)
* [Looping strategy](https://developer.harness.io/harness-platform/use-harness-platform/pipelines/looping-strategies/looping-strategies-matrix-repeat-and-parallelism)
* [Policy enforcement](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/advanced/cd-governance/harness-governance-overview.md)

***

## Review the example <a href="#test" id="test"></a>

The following example shows how Queue steps work.

The YAML below is a pipeline with a Custom stage. The stage has a Queue step, then a [shell script](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/utilities/shell-script-step.md) step that runs Bash `sleep 30`.

You can copy it and paste it into your Harness project. Update `projectIdentifier` and `orgIdentifier` to match your project and organization.

```yaml
pipeline:  
    name: Queue  
    identifier: Queue  
    projectIdentifier: queuesteptest  
    orgIdentifier: default  
    tags: {}  
    stages:  
        - stage:  
              name: Queue  
              identifier: Queue  
              description: ""  
              type: Custom  
              spec:  
                  execution:  
                      steps:  
                          - step:  
                                type: Queue  
                                name: Queue  
                                identifier: Queue  
                                spec:  
                                    key: "123"  
                                    scope: Pipeline  
                                timeout: 10m  
                          - step:  
                                type: ShellScript  
                                name: Sleep  
                                identifier: Sleep  
                                spec:  
                                    shell: Bash  
                                    onDelegate: true  
                                    source:  
                                        type: Inline  
                                        spec:  
                                            script: sleep 30  
                                    environmentVariables: []  
                                    outputVariables: []  
                                    executionTarget: {}  
                                timeout: 10m  
              tags: {}
```

When you finish, the pipeline looks like this:

![Pipeline with a Queue step followed by a Sleep step](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-3f8b5f668e74fee7bb719d6b161b2a6e023017b8%2Fcontrol-resource-usage-with-queue-steps-04.png?alt=media)

Open the **Queue** step.

**Run next queued execution after completion of** is set to **Pipeline**. The pipeline must finish before any other queued pipeline executions can proceed.

Run this pipeline twice in a row.

The first run of the pipeline runs without queuing. The second run stays queued until the first run is complete.

The first run shows the pipeline execution running (**Running**) and the other pipeline execution queued.

![First pipeline run in progress with a second run queued](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-92dc834f4138080edbc902286f7d1ba1ba87c3e0%2Fcontrol-resource-usage-with-queue-steps-05.png?alt=media)

Click the name of the queued pipeline to open its execution.

The second run:

![Second pipeline run queued while another run is in progress](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-e97b9619f4c75f5d2bf144ca1a220b985bfcf4db%2Fcontrol-resource-usage-with-queue-steps-06.png?alt=media)

The pipeline execution is queued (**Current**), and the pipeline execution that is running is shown.

This example uses multiple executions of the same pipeline. If a Queue step is added to another pipeline and uses the same resource key, the same queuing process applies to that pipeline.

The pipeline **queue 2** uses the same Queue step resource key. It waits for the **Queue** pipeline to complete.

![Pipeline queue 2 waiting for the Queue pipeline](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-4af73cdfcf9a7b43840b242fe1ff3b5cc4467c4a%2Fcontrol-resource-usage-with-queue-steps-07.png?alt=media)

***

## Queue step scope <a href="#queue-step-scope" id="queue-step-scope"></a>

Queue steps apply across the account.

{% hint style="warning" %}
**Account-wide**

Queue steps are account-wide. If a Queue step is placed in one pipeline, it restricts any other pipeline in the account from using resources until it is safe to use.
{% endhint %}

***

## Barriers, resource constraints, and Queue steps <a href="#barriers-resource-constraints-and-queue-steps" id="barriers-resource-constraints-and-queue-steps"></a>

Harness has several ways to control deployments and resource usage. Compare how they differ.

For more information, go to [Controlling resource usage with Barriers, Resource Constraints, and Queue steps](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/flow-control/controlling-deployments-with-barriers-resource-constraints-and-queue-steps.md).

***

## When to queue <a href="#when-to-queue" id="when-to-queue"></a>

Queue steps can be added anywhere in your stage. Add one wherever the resource you want to protect is used.

For example, if pipeline A performs Terraform provisioning and pipeline B deploys to the provisioned infrastructure, place the Queue step before the [Terraform Apply](https://developer.harness.io/continuous-delivery/use-continuous-delivery/provision-infrastructure/terraform-infra/run-a-terraform-plan-with-the-terraform-apply-step.md) step in pipeline A, and before the deployment step in pipeline B, such as a Kubernetes [Rolling step](https://developer.harness.io/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/kubernetes-executions/create-a-kubernetes-rolling-deployment.md).

***

## Next steps

* [Controlling resource usage with Barriers, Resource Constraints, and Queue steps](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/flow-control/controlling-deployments-with-barriers-resource-constraints-and-queue-steps.md): Compare barriers, resource constraints, and Queue steps.
* [Shell script step](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/utilities/shell-script-step.md): Run a script after the Queue step, as the example does with `sleep 30`.
* [Terraform Apply](https://developer.harness.io/continuous-delivery/use-continuous-delivery/provision-infrastructure/terraform-infra/run-a-terraform-plan-with-the-terraform-apply-step.md): Place a Queue step before provisioning when another pipeline deploys to that infrastructure.
* [Create a Kubernetes rolling deployment](https://developer.harness.io/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/kubernetes-executions/create-a-kubernetes-rolling-deployment.md): Place a Queue step before a rolling deployment that shares a namespace.

{% @harness-feedback/feedback %}
