> 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-integration/use-harness-ci/use-harness-ci/manage-dependencies/ci-saucelabs-background-step.md).

# Run a Sauce Connect Proxy service

Run Sauce Connect Proxy in a Background step in a Build stage.

In Harness CI, you use [Background steps](/continuous-integration/use-harness-ci/use-harness-ci/manage-dependencies/background-step-settings.md) to [manage services](/continuous-integration/use-harness-ci/use-harness-ci/manage-dependencies/dependency-mgmt-strategies.md) that need to run for the entire lifetime of a Build stage. To demonstrate how you can use Background steps, this topic explains how to run [Sauce Connect Proxy](https://docs.saucelabs.com/secure-connections/sauce-connect/) in a Background step. [Sauce Labs](https://saucelabs.com/) is a web and mobile application automated testing platform. Sauce Connect Proxy can run as a Background step in your Harness CI pipeline, and act as a proxy server between a Sauce Labs infrastructure and your CI pipeline.

### Add a Background step <a href="#add-a-background-step" id="add-a-background-step"></a>

1. Create a [Harness text secret](/harness-ai/use-harness-platform/secrets/add-use-text-secrets.md) containing a [Sauce Labs Access Key](https://docs.saucelabs.com/secure-connections/sauce-connect/setup-configuration/environment-variables/#user-credentials-environment-variables). Make note of the secret's **ID**.
2. [Create a Harness CI pipeline](/continuous-integration/use-harness-ci/use-harness-ci/prep-ci-pipeline-components.md) and add a [Build stage](/continuous-integration/use-harness-ci/use-harness-ci/set-up-build-infrastructure/ci-stage-settings.md).

   You can [disable clone codebase](/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/create-and-configure-a-codebase.md#disable-clone-codebase-for-specific-stages), because the pipeline created in this example doesn't need to pull any source code.
3. You can use Background steps with any build infrastructure. To follow along with this example, use either [Harness Cloud build infrastructure](/continuous-integration/use-harness-ci/use-harness-ci/set-up-build-infrastructure/use-harness-cloud-build-infrastructure.md#use-harness-cloud) or a [Kubernetes cluster build infrastructure](/continuous-integration/use-harness-ci/use-harness-ci/set-up-build-infrastructure/k8s-build-infrastructure/set-up-a-kubernetes-cluster-build-infrastructure.md).
4. Add a [Background step](/continuous-integration/use-harness-ci/use-harness-ci/manage-dependencies/background-step-settings.md) configured as follows:
   * **Name:** Enter a name, such as `sauce_connect`.
   * **Container Registry:** Select a Docker connector.
   * **Image:** Enter the name and tag of a Sauce Connect Docker image, such as `saucelabs/sauce-connect:latest`.
   * **Environment Variables:** Add two environment variables for your Sauce Labs credentials:
     * `SAUCE_USERNAME: YOUR_SAUCE_LABS_USERNAME`
     * `SAUCE_ACCESS_KEY: <+secrets.getValue('YOUR_SAUCE_ACCESS_KEY_SECRET_ID')>`
   * **Port Bindings:** If you chose Harness Cloud build infrastructure, add port bindings `"8032": "8032"`. For more information, go to [Background step settings - Port bindings](/continuous-integration/use-harness-ci/use-harness-ci/manage-dependencies/background-step-settings.md#port-bindings).
5. Select **Apply Changes** to save the Background step.

### Add a health check <a href="#add-a-health-check" id="add-a-health-check"></a>

Harness recommends adding health checks for Background steps. This example runs a cURL command to poll the `readiness` of the Sauce Connect service until it returns a successful response. This ensures that Sauce Connect is ready to receive traffic before the pipeline continues.

In your pipeline's Build stage, after the Background step, add a [Run step](/continuous-integration/use-harness-ci/use-harness-ci/run-step-settings.md) configured as follows:

* **Name**: Enter a name, such as `wait for SC`.
* **Container Registry** and **Image**: With a Kubernetes cluster build infrastructure, select a Docker connector and enter the image `curlimages/curl:7.83.1`. With Harness Cloud, these are not required because Harness Cloud runners already have the required cURL binary.
* **Shell**: Select **Bash**
* **Command:** Enter the following:

```
until [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8032/readiness)" == "200" ]
do
  sleep 2
done
echo "SC ready"
```

### Run the pipeline <a href="#run-the-pipeline" id="run-the-pipeline"></a>

Save the pipeline, select **Run**, and then select **Run Pipeline**.

While the build runs, you can observe the logs. When Sauce Connect is ready, the health check step prints `SC ready`.

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

Here's the YAML for the Build stage created in this topic. A complete Harness CI pipeline would have additional steps after the Run step that build code, run tests, push images, and so on. Some or all of these steps might interact with the Sauce Labs Proxy service running in the background.

{% tabs %}
{% tab title="Harness Cloud" %}

```yaml
stages:
  - stage:
      name: build
      identifier: build
      description: ""
      type: CI
      spec:
        cloneCodebase: false ## Clone codebase is disabled for this example.
        platform: ## This stage uses Harness Cloud build infrastructure.
          os: Linux
          arch: Amd64
        runtime:
          type: Cloud
          spec: {}
        execution:
          steps:
            - step: ## Background step runs the Sauce Connect Docker image.
                type: Background
                name: Sauce Connect
                identifier: Sauce_Connect
                spec:
                  connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR
                  image: saucelabs/sauce-connect
                  shell: Sh
                  envVariables:
                    SAUCE_USERNAME: YOUR_SAUCE_LABS_USERNAME
                    SAUCE_ACCESS_KEY: <+secrets.getValue('Sauce_Access_Key')>
                  portBindings:
                    "8032": "8032"
            - step: ## Run step checks that Sauce Connect is healthy before allowing other steps to run.
                type: Run
                name: Wait for SC
                identifier: Wait_for_SC
                spec:
                  shell: Bash
                  command: |-
                    until [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8032/readiness)" == "200" ]
                    do
                      sleep 2
                    done
                    echo "SC ready"
```

{% endtab %}

{% tab title="Kubernetes cluster" %}

```yaml
stages:
  - stage:
      name: build
      identifier: build
      description: ""
      type: CI
      spec:
        cloneCodebase: false ## Clone codebase is disabled for this example.
        infrastructure: ## This pipeline uses a Kubernetes cluster build infrastructure
          type: KubernetesDirect
          spec:
            connectorRef: YOUR_KUBERNETES_CLUSTER_CONNECTOR
            namespace: YOUR_KUBERNETES_NAMESPACE
            automountServiceAccountToken: true
            nodeSelector: {}
            os: Linux
        execution:
          steps:
            - step: ## Background step runs the Sauce Connect Docker image.
                type: Background
                name: Sauce Connect
                identifier: Sauce_Connect
                spec:
                  connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR
                  image: saucelabs/sauce-connect
                  shell: Sh
                  envVariables:
                    SAUCE_USERNAME: YOUR_SAUCE_LABS_USERNAME
                    SAUCE_ACCESS_KEY: <+secrets.getValue('Sauce_Access_Key')>
            - step: ## Run step checks that Sauce Connect is healthy before allowing other steps to run.
                type: Run
                name: Wait for SC
                identifier: Wait_for_SC
                spec:
                  connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR
                  image: curlimages/curl:7.83.1
                  shell: Sh
                  command: |-
                    until [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8032/readiness)" == "200" ]
                    do
                      sleep 2
                    done
                    echo "SC ready"
```

{% endtab %}
{% endtabs %}

{% @harness-feedback/feedback %}
