Get orb version as environment variable while running job

Hello!

We have authored a CircleCI orb. It’s relatively simple, this is what it does:

  • record the current CIRCLE_BRANCH, CIRCLE_PROJECT_REPONAME, CIRCLE_PROJECT_USERNAME
  • make a call to our API with the above information
  • return some value to the user to be used for other jobs

A user can use any version of the orb. We would like to identify the version of the orb that the job is using, and pass that to the API. I do not see a corresponding env var in the current list. Is there an environment variable (or could we request one) to get the version of the orb currently used?

1 Like

Hi @elliott-king ,

Thanks for sharing the details!
I understand the problem as: How can an Orb know which version it is itself, so that it can use that information (e.g., sending it as part of a payload to an API endpoint)?

I also noted you have filed a feature request on our Ideas board here. Thank you!

Currently, there is no direct way to retrieve that information within the scope of the Orb’s operation. In other words, I understand that there is no existing environment variables or so to reveal the Orb version.

The workaround I can think of right now, is to simply pass the orb version as a command / job parameter then. This is definitely not the “smartest” way, but arguably simple although slightly labored in my opinion.

version: 2.1

orbs:
 my_orb: &my_orb_version my_namespace/my_orb@0.1.0

workflows:
  my_workflow:
    jobs:
      - my_orb/audit:
          # passes the fully qualified namespace/orb@version
          version: *my_orb_version

This would mean updating the Orb’s job / command definition to take in a new parameter then.

Hope this helps provide a next step for now!