June 13, 2024

Running CircleCI Orbs Without CircleCI

Table of Contents

Although designed for CircleCI, many Orbs can run locally or in other environments like Harness CI

Software automation ecosystems have exploded. Services like GitHub Actions, Drone, and CircleCI all have strong communities building tooling around Actions, Drone Plugins, and CircleCI Orbs

Orbs encapsulate reusable pieces of configuration, enabling developers to avoid repeating configuration for common tasks such as installing tools, running tests, and sending notifications. When using an Orb, developers don’t have to build the required logic for their pipelines themselves; they can leverage the community to develop and maintain the Orb.

Migrating to a new continuous integration service can often be daunting for developers and engineers tasked with maintaining automation pipelines. Orbs can provide capabilities and functionality requiring significant resources to rewrite for a different platform. While Orbs are designed to run in CircleCI pipelines, it is possible to run many Orbs both locally and in alternate environments, such as Harness CI.

CircleCI Local CLI

The CircleCI local command line interface (CLI) can run jobs that use the Docker execution environment locally. 

For example, this configuration uses the shellcheck Orb to check for bugs and errors in shell scripts in your repository’s scripts directory.

version: '2.1'
orbs:
  shellcheck: circleci/shellcheck@3.2.0
workflows:
  my_workflow:
    jobs:
      - shellcheck/check:
          dir: ./scripts

If your repository contains this file at .circleci/config.yml, you can run the job locally from the root of your repository with this command

$ circleci local execute shellcheck/check
CircleCI CLI Local Executon

Harness Cloud infrastructure can execute this command in a pipeline run step.

Here is a Harness CI pipeline with two steps. The first step installs the CircleCI CLI; the second step executes the shellcheck/check job.

- step:
    type: Run
    name: Install CLI
    identifier: install_cli
    description: Install the CircleCI CLI
    spec:
      shell: Sh
      command: curl -fLSs https://circle.ci/cli | bash

- step:
    type: Run
    name: Shellcheck
    identifier: shellcheck
    description: Run the shellcheck/check job
    spec:
      shell: Sh
      command: circleci local execute shellcheck/check
CircleCI CLI in Harness CI Pipeline Execution

CircleCI Orbs Are Scripts

Under the hood, Orbs are scripts. These scripts can be executed outside the CircleCI environment by setting the necessary environment variables and running scripts within the Orb repository.

Here is an example CircleCI configuration file. This configuration contains a job that uses the Browser Tools Orb to install version 116.0.5845.187 of the Chrome browser.

version: '2.1'
orbs:
  browser-tools: circleci/browser-tools@1.4.8
jobs:
  my_workflow:
    executor: browser-tools/default
    steps:
      - browser-tools/install-chrome:
          replace-existing: true
          chrome-version: 116.0.5845.187
          channel: stable

Here is an equivalent Harness CI pipeline step that runs the install-chrome.sh script directly from the cloned browser-tools-orb Git repository. Orb scripts require parameters to be passed via environment variables prefixed by ORB_PARAM_. For example, the chrome-version parameter is passed as ORB_PARAM_CHROME_VERSION.

- step:
    type: Run
    name: Install Chrome
    identifier: install_chrome
    description: Run the install-chrome.sh script
    spec:
      shell: Sh
      envVariables:
        BROWSER_TOOLS_ORB_VERSION: v1.4.8
        ORB_PARAM_CHANNEL: stable
        ORB_PARAM_CHROME_VERSION: 116.0.5845.187
      command: |-
        git clone \
          --depth 1 \
          --branch $BROWSER_TOOLS_ORB_VERSION \
          https://github.com/CircleCI-Public/browser-tools-orb.git \
          /tmp/browser-tools-orb
        bash /tmp/browser-tools-orb/src/scripts/install-chrome.sh

CircleCI Orb Script in Harness CI Pipeline Execution

Conclusion

In just a few minutes, you can start experimenting with running CircleCI Orbs locally and in alternate environments, avoiding rewriting or migrating Orbs you rely on.

Resources:

Continuous Integration