> 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-gitops/argo-rollouts/gitops-sync-with-multiple-rollouts-steps.md).

# GitOps Sync with multiple Rollout steps

Learn how to pass values between GitOps Rollout steps using Harness expressions.

This advanced example demonstrates a complete pipeline that starts with a GitOps sync step followed by multiple GitOps Rollout steps, showing how to pass values between steps.

## What you will learn from this topic

* Understand [how a multi-rollout pipeline is structured](#pipeline-overview), from image update through sync to multiple resume steps.
* How to [reference outputs from the GitOps Sync step](#how-to-get-values-from-previous-steps) using Harness expressions.
* How to [configure each GitOps Rollout step](#step-by-step-explanation) with dynamic values from previous steps.
* Understand the [recommended patterns](#best-practices) for building reliable rollout pipelines.

## Before you begin

Before you begin, make sure you have the following:

* You need a Harness GitOps Agent installed and connected. Go to [Install a Harness GitOps Agent](https://developer.harness.io/continuous-delivery/use-gitops/gitops-entities/agents/install-a-harness-git-ops-agent.md) to set one up.
* You need an Argo Rollouts installation. Go to [Argo Rollouts overview](https://developer.harness.io/continuous-delivery/use-gitops/argo-rollouts/argo-rollouts-overview.md) to get started.

## Overview <a href="#overview" id="overview"></a>

Harness provides an expression system to access outputs from previous steps. This enables dynamic configuration where steps automatically discover and use the correct rollout details without hardcoding values.

## Key benefits <a href="#key-benefits" id="key-benefits"></a>

Using expressions to pass values between steps provides the following benefits:

1. **Dynamic configuration**: Steps automatically discover and use the correct rollout details
2. **Reusability**: The same pipeline can work across different environments and applications
3. **Error reduction**: No hardcoded values that could become outdated
4. **Maintainability**: Changes to rollout names or namespaces are automatically reflected

## Pipeline overview <a href="#pipeline-overview" id="pipeline-overview"></a>

{% hint style="info" %}
**Feature flag requirement**

To use Argo Rollouts with Harness GitOps pipelines, ensure the `CDS_GITOPS_ENABLE_ROLLOUTS_PIPELINE_UX` feature flag is enabled in your Harness account.
{% endhint %}

Here is a visual representation of the pipeline:

![GitOps Pipeline with multiple Rollout steps](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-07bc0f256d9710039261ab35d4e55a9d523d4499%2Frollout-13.png?alt=media)

This pipeline consists of the following key steps:

1. **Update Rollout Image**: Updates the image tag in your GitOps Application's manifest
2. **GitOps Sync**: Synchronizes the GitOps Application to apply the image update, which triggers a new rollout
3. **Resume First Pause for Rollout**: Resumes the rollout from the first pause step
4. **Any Intermediate Steps**: Optional placeholder steps for custom logic
5. **Resume Second Pause for Rollout**: Resumes the rollout from the second pause step
6. **Handle Degraded Rollout**: Handles degraded rollout states with retry action
7. **Conditional Execution For Rollout**: Conditional execution based on application name

## Pipeline YAML <a href="#pipeline-yaml" id="pipeline-yaml"></a>

The following pipeline YAML defines the complete example:

```yaml
pipeline:
  name: RolloutStepExample
  identifier: RolloutStepExample
  projectIdentifier: <PROJECT_ID>
  orgIdentifier: default
  tags: {}
  stages:
    - stage:
        name: gs1
        identifier: gs1
        description: ""
        type: Deployment
        spec:
          deploymentType: Kubernetes
          gitOpsEnabled: true
          service:
            serviceRef: svc1
          execution:
            steps:
              - step:
                  type: UpdateGitOpsApp
                  name: Update Rollout Image
                  identifier: Update_Rollout_Image
                  spec:
                    targetRevision: master
                    kustomize:
                      images:
                        - argoproj/load-tester:latest
                        - argoproj/rollouts-demo:yellow
                      replicas: []
                    applicationName: app-rollout-example
                    agentId: <AGENT_ID>
                  timeout: 10m
              - step:
                  type: GitOpsSync
                  name: GitOpsSync_1
                  identifier: GitOpsSync_1
                  spec:
                    prune: false
                    dryRun: false
                    applyOnly: false
                    forceApply: false
                    applicationsList:
                      - applicationName: app-rollout-example
                        agentId: <AGENT_ID>
                    retryStrategy: {}
                    retry: false
                    syncOptions:
                      skipSchemaValidation: false
                      autoCreateNamespace: false
                      pruneResourcesAtLast: false
                      applyOutOfSyncOnly: false
                      replaceResources: false
                      prunePropagationPolicy: foreground
                  timeout: 10m
              - step:
                  type: GitOpsRollout
                  name: Resume First Pause for Rollout
                  identifier: Resume_First_Pause_for_Rollout
                  spec:
                    appName: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].appName>
                    agentIdentifier: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].agentIdentifier>
                    namespace: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].namespace>
                    rolloutName: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].rolloutName>
                    waitUntilHealthStatus:
                      healthStatus: Suspended
                    autoRolloutAction: resume
                  timeout: 10m
                  failureStrategies:
                    - onFailure:
                        errors:
                          - AllErrors
                        action:
                          type: Ignore
              - step:
                  type: Wait
                  name: Any intermediate steps
                  identifier: Any_intermediate_steps
                  spec:
                    duration: 30s
              - step:
                  type: GitOpsRollout
                  name: Resume Second Pause for Rollout
                  identifier: Resume_Second_Pause_for_Rollout
                  spec:
                    appName: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].appName>
                    agentIdentifier: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].agentIdentifier>
                    namespace: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].namespace>
                    rolloutName: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].rolloutName>
                    waitUntilHealthStatus:
                      healthStatus: Suspended
                    autoRolloutAction: resume
                  timeout: 10m
                  failureStrategies:
                    - onFailure:
                        errors:
                          - AllErrors
                        action:
                          type: Ignore
              - step:
                  type: GitOpsRollout
                  name: Handle Degraded Rollout
                  identifier: Handle_Degraded_Rollout
                  spec:
                    appName: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].appName>
                    agentIdentifier: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].agentIdentifier>
                    namespace: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].namespace>
                    rolloutName: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].rolloutName>
                    autoRolloutAction: retry
                  timeout: 10m
                  when:
                    stageStatus: Failure
              - step:
                  type: GitOpsRollout
                  name: Conditional Execution For Rollout
                  identifier: Conditional_Execution_For_Rollout
                  spec:
                    appName: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].appName>
                    agentIdentifier: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].agentIdentifier>
                    namespace: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].namespace>
                    rolloutName: <+execution.steps.GitOpsSync_1.gitops.discoveredRollouts[0].rolloutName>
                    autoRolloutAction: restart
                  timeout: 10m
                  when:
                    stageStatus: All
                    condition: <+pipeline.stages.gs1.spec.execution.steps.GitOpsSync_1.gitops.applications[0].name>=="app-rollout-example"
            rollbackSteps: []
          environment:
            environmentRef: env1
            deployToAll: true
        tags: {}
        failureStrategies:
          - onFailure:
              errors:
                - AllErrors
              action:
                type: StageRollback

```

## Get values from previous steps <a href="#how-to-get-values-from-previous-steps" id="how-to-get-values-from-previous-steps"></a>

Harness provides an expression system to access outputs from previous steps. Here is how it works:

### GitOps Sync outputs <a href="#id-1-accessing-gitops-sync-outputs" id="id-1-accessing-gitops-sync-outputs"></a>

The GitOps Sync step outputs discovered rollouts that can be used in subsequent steps:

```
<+execution.steps.<step_identifier>.gitops.discoveredRollouts[<index>].<field>>
```

![Expression Syntax](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-2fb7e21bacdc50d9302683a45a057cf0410e2742%2Frollout-14.png?alt=media)

**Available fields**:

* `agentIdentifier` - The GitOps agent identifier
* `appName` - The GitOps application name
* `rolloutName` - The Rollout resource name
* `namespace` - The namespace where the rollout is deployed

### Expression examples <a href="#id-2-expression-examples" id="id-2-expression-examples"></a>

```yaml
# Get the first discovered rollout's agent
<+execution.steps.gitops_sync_step.gitops.discoveredRollouts[0].agentIdentifier>

# Get the rollout name
<+execution.steps.gitops_sync_step.gitops.discoveredRollouts[0].rolloutName>

# Get the namespace
<+execution.steps.gitops_sync_step.gitops.discoveredRollouts[0].namespace>
```

### Multiple rollouts <a href="#id-3-multiple-rollouts" id="id-3-multiple-rollouts"></a>

If you have multiple rollouts, access them by index:

```yaml
# First rollout
<+execution.steps.gitops_sync_step.gitops.discoveredRollouts[0].rolloutName>

# Second rollout
<+execution.steps.gitops_sync_step.gitops.discoveredRollouts[1].rolloutName>
```

### Outputs from other steps <a href="#id-4-accessing-other-step-outputs" id="id-4-accessing-other-step-outputs"></a>

You can also access outputs from other step types:

```yaml
# Access shell script outputs
<+execution.steps.shell_step.output.outputVariables.VAR_NAME>

# Access HTTP response
<+execution.steps.http_step.output.responseBody>

# Access artifact information
<+execution.steps.build_step.output.artifactPath>
```

## Step-by-step explanation <a href="#step-by-step-explanation" id="step-by-step-explanation"></a>

### Update the rollout image <a href="#step-1-update-rollout-image" id="step-1-update-rollout-image"></a>

The following details apply to this step:

* **Purpose**: Updates the container image in your GitOps Application's manifest
* **Configuration**: Uses the `UpdateGitOpsApp` step to modify the image tag in the rollout manifest
* **Key settings**:
  * `targetRevision`: Git branch containing your manifests
  * `kustomize.images`: Specify the new image to deploy
  * `applicationName`: Your GitOps Application name
  * `agentId`: GitOps Agent identifier

### GitOps Sync <a href="#step-2-gitops-sync" id="step-2-gitops-sync"></a>

The following details apply to this step:

* **Purpose**: Synchronizes the GitOps Application to apply the image update
* **Configuration**: Uses the `GitOpsSync` step to trigger a sync operation
* **Key settings**:
  * `applicationsList`: List of applications to sync
  * `syncOptions`: Various sync configuration options
  * `timeout`: Maximum time to wait for sync completion

### Resume first pause for rollout <a href="#step-3-resume-first-pause-for-rollout" id="step-3-resume-first-pause-for-rollout"></a>

The following details apply to this step:

* **Purpose**: Resumes the rollout from the first pause step
* **Configuration**: Uses the `GitOpsRollout` step with resume action
* **Key settings**:
  * `autoRolloutAction`: Set to `resume`
  * `waitUntilHealthStatus`: Set to `Suspended` to wait for pause state
  * Uses expressions from the Sync step to get rollout details
  * `failureStrategies`: Ignore errors to continue pipeline

### Any intermediate steps <a href="#step-4-any-intermediate-steps" id="step-4-any-intermediate-steps"></a>

The following details apply to this step:

* **Purpose**: Placeholder for custom logic or additional processing
* **Configuration**: Uses the `Wait` step for simple delays
* **Use cases**:
  * Add custom validation logic
  * Insert additional processing steps
  * Create delays between operations

### Resume second pause for rollout <a href="#step-5-resume-second-pause-for-rollout" id="step-5-resume-second-pause-for-rollout"></a>

The following details apply to this step:

* **Purpose**: Resumes the rollout from the second pause step
* **Configuration**: Uses the `GitOpsRollout` step with resume action
* **Key settings**:
  * `autoRolloutAction`: Set to `resume`
  * `waitUntilHealthStatus`: Set to `Suspended` to wait for pause state
  * Uses expressions from the Sync step to get rollout details

### Handle degraded rollout <a href="#step-6-handle-degraded-rollout" id="step-6-handle-degraded-rollout"></a>

The following details apply to this step:

* **Purpose**: Handles degraded rollout states with retry action
* **Configuration**: Uses the `GitOpsRollout` step with retry action
* **Key settings**:
  * `autoRolloutAction`: Set to `retry`
  * `when`: Set to `Failure` to only run on stage failure
  * Uses expressions from the Sync step to get rollout details

### Conditional execution for rollout <a href="#step-7-conditional-execution-for-rollout" id="step-7-conditional-execution-for-rollout"></a>

The following details apply to this step:

* **Purpose**: Conditional execution based on application name
* **Configuration**: Uses the `GitOpsRollout` step with restart action
* **Key settings**:
  * `autoRolloutAction`: Set to `restart`
  * `when`: Conditional execution with custom condition
  * Uses expressions to check application name

## Best practices <a href="#best-practices" id="best-practices"></a>

Apply the following practices when building pipelines with multiple GitOps Rollout steps.

1. **Use descriptive step identifiers** for easier reference
2. **Add timeout values** appropriate for your deployment size
3. **Include health checks** for critical production deployments
4. **Consider manual approval steps** for production environments
5. **Test expressions** in the pipeline editor before saving

## Next steps

You have learned how to build a multi-rollout GitOps pipeline and pass values between steps using Harness expressions. The following resources cover related topics.

* [Managing rollouts in Harness pipeline](https://developer.harness.io/continuous-delivery/use-gitops/argo-rollouts/managing-rollouts-in-harness-pipelines.md): Manage rollouts from within a Harness pipeline.
* [GitOps pipeline steps](https://developer.harness.io/continuous-delivery/use-gitops/pr-pipelines/pr-pipelines-basics.md#gitops-pipeline-steps): Review the GitOps pipeline step reference.
* Go to the [Argo Rollouts Official Documentation](https://argoproj.github.io/argo-rollouts/) for the full Argo Rollouts reference.
* Go to the [Argo Rollouts kubectl Plugin](https://argoproj.github.io/argo-rollouts/features/kubectl-plugin/) for the kubectl plugin reference.

{% @harness-feedback/feedback %}
