Skip to main content

Run Sauce Connect Proxy as a Background Step

Background steps are useful for running services that need to run for the entire lifetime of a Build stage. This tutorial shows how to run Sauce Connect Proxy as a Background step in a Harness CI pipeline.

Sauce Labs 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.

tip

If you don't have a Harness account yet, you can create one for free at app.harness.io.

Create your pipeline

Docker Hub connector

You need a Docker Hub connector. In this example, the connector is used to authenticate to pull Docker images from Docker Hub.

If you have not created a Docker Hub connector yet, follow these steps.

Create connector

  1. From the left pane, expand the Project Setup, and then select Connectors.
  2. Select + New Connector, and then select Docker Registry.
  3. In the Name field, enter Docker Hub, and then select Continue.
  4. In the Docker Registry URL field, enter https://index.docker.io/v2/.
  5. For Provider Type, select Docker Hub.
  6. In the Username field, enter your Docker Hub username.
  7. In the Password field, select Create or Select a Secret. Follow the prompts to add your Docker Hub access token, and then click Continue.
  8. At the next screen, select Connect through Harness Platform, and then select Save and Continue.
  9. After Harness performs a validation test, select Finish.
  10. In your list of connectors, note the ID of the connector that you just created. If you named the connector Docker Hub, the ID should be Docker_Hub.

info

This connector needs an access token with Read-only permissions.

Create secret

  1. From the left pane, expand the Project Setup menu, and then select Secrets.
  2. Select + New Secret, then select Text.
  3. In the Secret Name field, enter Sauce Access Key.
  4. In the Secret Value field, enter your Sauce Labs access key, then click Save.

Modify the pipeline

  1. From the left pane, select Pipelines, then select + Create a Pipeline.
  2. In the Name field, enter a name for your pipeline, then select Start.
  3. Switch from the Visual view to the YAML view, and then select Edit YAML.

Append the following configuration:

Cloud pipelines run in managed infrastructure provided by Harness.

  variables:
- name: SAUCELABS_USERNAME
type: String
description: Your Sauce Labs username
value: <+input>
stages:
- stage:
name: Sauce Connect
identifier: Sauce_Connect
description: ""
type: CI
spec:
cloneCodebase: false
platform:
os: Linux
arch: Amd64
runtime:
type: Cloud
spec: {}
execution:
steps:
- step:
type: Background
name: Sauce Connect
identifier: Sauce_Connect
spec:
connectorRef: Docker_Hub
image: saucelabs/sauce-connect
shell: Sh
envVariables:
SAUCE_USERNAME: <+pipeline.variables.SAUCELABS_USERNAME>
SAUCE_ACCESS_KEY: <+secrets.getValue('Sauce_Access_Key')>
portBindings:
"8032": "8032"
- step:
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"
info

This configuration requires the Docker Hub connector ID to be Docker_Hub. If your connector ID is different, replace Docker_Hub with the correct ID.

Select Save in the YAML editor.

Run your pipeline

  1. In the Pipeline Studio, select Run.
  2. Enter your Sauce Labs username in the SAUCELABS_USERNAME field. If you created a Kubernetes pipeline, enter the namespace in the KUBERNETES_NAMESPACE field.
  3. Select Run Pipeline.
  4. Observe each step of the pipeline execution. When Sauce Connect is ready, the Wait for SC step will print SC ready.