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.

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

__wf_reserved_inherit
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.

__wf_reserved_inherit
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.

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.

__wf_reserved_inherit
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