Showing posts with label CircleCI. Show all posts
Showing posts with label CircleCI. Show all posts

Try CircleCI Orb

CircleCI is one of the popular Countinuous Integration and Continuous Delivery Platform. With CircleCI you can create your pipeline through code. You need to write your CI/CD job, steps and required commands in yml format as shown in sample configuration file below.

With the configuration file placed in your code repository under .circleci directory is automatically considered by CircleCI Cloud which reads this file and executes the jobs.

CircleCI Orb is nothing but a reusable package. In your CircleCI jobs, you may need to run similar commands repetitively, you can simply create an orb doing that comman thing and make your CircleCI configuration more readable and maintanable.

How to create orb?

Creating and sharing orb is made very simple by CircleCI team. You can simply use this template and follow the instructions given in README file that's it! To summarize you need to follow below steps which I followed to create a simple orb,

  • Sign up to CircleCI using GitHub
  • Install CircleCI CLI
  • Create CircleCI namespace for your organization (or user in case you don't have any organization) if not already,
    • circleci namespace create <name> --org-id <your-organization-id>
  • Initialize orb, choose to download template straight away
    • circleci orb init <your-orb-name>







  • Push your changes to GitHub repository
  • Check whether CircleCI pipelines running successfully or not. (ssh or lint checks may fail, you need to fix them and commit the changes until all steps succeed)
  • Create Release with v0.0.1 tag on GitHub
  • If everything is green on CircleCI, visit your orb registry to see your first orb!
    • https://circleci.com/developer/orbs/orb/<your-namespace>/<your-orb>
For developing and testing orb, you can create a separate branch which will publish development version, you can finally merge this development branch into master when you have something to release to your public registry.

notiforb

I have created a simple public orb called, notiforb which is kind of utility to send notification from your CircleCI pipeline to Google Chat (and more in future). To send message to Google Chat you can simply add following to your CircleCI configuration file. 

1. Import Orb into your CircleCI config.

orbs:
  notiforb: akash-ccn/notiforb@0.0.1

2. Use command in Job step.

  - notiforb/gchat-notify:
      message: "Hi, this is CircleCI notifORB!"

Here multiple things happen behind the scene in gchat-notify command which is taken care inside orb. Now let's see what we have in orb code.

commands: Consider them as functions of programming where your pass parameters and execute some instructions.

jobs: Sample jobs to describe usage of orb in CircleCI registry.

examples : For showing how to use your orb.

executors : Environment where commands of orb can be executed. Depending on your orb you may or may not require executors.

@orb.yml : Contains description and display information.

scripts: Majorly in CircleCI execution we execute shell scripts on some virtual machine or container. This directory contains all scripts that are used in notiforb. 

templates : This directory is specific to notiforb which contains Google Chat webhook request template to be used for sending messages.



Here the example orb is very basic and created for learning purpose only, but you can move boilerplate code to orb whether it can be comman shell script, executors, validations etc. CircleCI itself manages many public orbs and provides regular updates.


References :

  • CircleCI Orbs Overview 
  • notiforb - Source 
  • notiforb - CircleCI Registry
  • Code Smells

    Code smells are the indicators of potential flaws in the design and structure, not necessarily prevents the functionality but signifies the ...