Building an Orb in CircleCI (Elixir example)

David Magalhães
May 29 · 11 min read

What do you gain from using an orb

Orb structure

Executors

Providing a good default executor is useful, because it allows the user to not start using more complex stuff if they don’t need to, and it just works out of the box.

executors: 
default-with-fakes3:
docker:
— environment:
MIX_ENV: test
image: ‘circleci/elixir:1.6.5’
— image: ‘circleci/postgres:10.4-alpine-postgis-ram’
— image: ‘circleci/fakes3:0.2.4’

Orb commands

Build

Tests

Format

Coverage

Credo

Dialyzer

Deploy

Jobs

Parameters

Executors

executor: << parameters.executor >>
parameters:
...
executor:
default: default
description: Executor to be used in this job
type: executor

Checkout

Persist to workspace

persist-to-workspace: 
default: true
description: Should this job persist files to a workspace? Defaults to true
type: boolean
- when: 
...
condition: << parameters.persist-to-workspace >>
steps:
— persist_to_workspace:
paths:
— project
— .mix
— .hex
— .ssh
root: ~/

Attach Workspace

attach-workspace: 
default: false
description: > Boolean for whether or not to attach to an existing workspace. Default is false.
type: boolean
- when: 
condition: << parameters.attach-workspace >>
steps:
— attach_workspace:
at: ~/

Other parameters

Examples

orbs: 
elixir: coletiv/elixir@0.1.0
version: 2.1
workflows:
elixir-build-test-minimal:
jobs:
— elixir/build-and-test:
check-format: true
coveralls: true
credo: true
dialyzer: true
fakes3 -r $HOME/.s3bucket -p 4567 &
test: 
executor: default
steps:
— attach_workspace:
at: ~/
— run: fakes3 -r $HOME/.s3bucket -p 4567 &
— elixir/coveralls

Orb CI

Final thoughts


Coletiv

Thoughts, dreams and rants about technology and work life from the Coletiv team

Thanks to Tiago Duarte.

David Magalhães

Written by

Software Developer

Coletiv

Coletiv

Thoughts, dreams and rants about technology and work life from the Coletiv team