CircleCI - Enhance your CI/CD code with private orbs

  1. When closely looking into the job of sanity-dev and functional-dev the steps like “cache-repo, dependency-cache, Create artefacts directory, notify-google-chat” are repeatedly used. Since these are commonly used commands we may be using it in other projects as well
  2. Non Encapsulated way of writing config
  • Duplicate config code: Having duplicate code will make our code smelly and increases technical debt associated with it
  • Large config file: As the pipeline evolves, the configuration file grows in size and becomes difficult to manage

Types of Orbs:

some of the existing orbs we might have used
circleci orb publish ./orb.yml <namespace>/<orb-name>@dev:firstorb
circleci orb publish promote <namespace>/<orb-name>@dev:first patch

Create a orb with orb development kit:

  • circleci orb init: A CLI command to initialise a new orb project, and in the case of private, an extra — private attribute must be added
  • circleci orb pack: A CLI command that combines all YAML files for the entire project and packages them as a single YAML file at run time

Stages involved in creating Orb with ODK

  1. Create a new repository in GitHub, for our use case we have created a repo with name “e2e-test-orbs”
  2. Create a directory in local machine from where we want to initialise the orb creation process. Its recommended to have a directory with same name which we used for creating repository
  3. Open a terminal from the path where we want to create orbs and invoke below command
circleci orb init . --private
Image: After invoking init command one should choose orb name and other mandatory inputs to download template
  • orb-tools/lint: It’s an orb job from the orb tool that lint the orb’s YAML and syntax
  • orb-tools/pack: Packs and validates the orb source
  • orb-tools/review: This will run a suite of tests against our orb designed to find opportunities to implement best practices and improve the quality of the orb
  • shellcheck/check: Similar to YAML linting this will validate the shell scripts
  • orb-tools/publish: Once the above Job are passed at this stage, publish will create a development version of a job
  • orb-tools/continue: Once development version of orb is created, this job will invoke the next workflow which is available in test-deploy.yaml
Unit test example for bash scripts using bats-core
  • command-tests: Its a step where we run the integration step and verify the behaviour by asserting it
  • orb-tools/pack: As we saw in the introduction orbs are sharable config which is defined in orb.yaml. This job will Pack the orb source into a single “orb.yml” file and validates for orb config errors
  • orb-tools/publish: This will now create a production version of a orb
Note: Inside the publish job we can get the orb url. It can only be accessed by authorised members because of publishing it private
https://github.com/kowcikr/simple-mocha-test-with-orbs/blob/main/.circleci/config.yml

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store