CircleCI orbs are shareable packages of configuration elements, including jobs, commands, and executors. more information about orbs you can see here
The following example calls an Orb named hello-build that exists in the certified circleci namespace.
version: 2.1
orbs:
hello: circleci/[email protected]
workflows:
"Hello Workflow":
jobs:
- hello/hello-build
Executors define the environment in which the steps of a job will be run, allowing you to reuse a single executor definition across multiple jobs.
version: 2.1
executors:
my-executor:
docker:
- image: circleci/ruby:2.5.1-node-browsers
jobs:
my-job:
executor: my-executor
steps:
- run: echo outside the executor
See the Using Parameters in Executors section of the Reusing Config document for examples of parameterized executors.
A conditional step consists of a step with the key when
or unless
. Under the when
key are the subkeys condition
and steps
. The purpose of the when
step is customizing commands and job configuration to run on custom conditions (determined at config-compile time) that are checked before a workflow runs. See the Conditional Steps section of the Reusing Config document for more details.
Example:
version: 2.1
jobs: # conditional steps may also be defined in `commands:`
job_with_optional_custom_checkout:
parameters:
custom_checkout:
type: string
default: ""
machine: true
steps:
- when:
condition: <<parameters.custom_checkout>>
steps:
- run: echo "my custom checkout"
- unless:
condition: <<parameters.custom_checkout>>
steps:
- checkout
workflows:
build-test-deploy:
jobs:
- job_with_optional_custom_checkout:
custom_checkout: "any non-empty string is truthy"
- job_with_optional_custom_checkout
A command definition defines a sequence of steps as a map to be executed in a job, enabling you to reuse a single command definition across multiple jobs.
Example:
commands:
sayhello:
description: "A very simple command for demonstration purposes"
parameters:
to:
type: string
default: "Hello World"
steps:
- run: echo << parameters.to >>
Don't forget change version
versoin: 2.1
Move your steps to commands if you use YAML anchors of define in the job.
Use:
commands:
bundle_cache:
steps:
- restore_cache:
keys:
- repo-bundle-v2-{{ checksum ".ruby-version" }}-{{ checksum "Gemfile.lock" }}
- run: bundle install --path vendor/bundle
- save_cache:
key: repo-bundle-v2-{{ checksum ".ruby-version" }}-{{ checksum "Gemfile.lock" }}
paths:
- ~/repo/vendor/bundle
jobs:
build:
steps:
- bundle_cache
Instead:
references:
restore_bundle_cache: &restore_bundle_cache
restore_cache:
keys:
- repo-bundle-v2-{{ checksum ".ruby-version" }}-{{ checksum "Gemfile.lock" }}
bundle_install: &bundle_install
run:
name: Installing gems
command: bundle install --path vendor/bundle
save_bundle_cache: &save_bundle_cache
save_cache:
key: repo-bundle-v2-{{ checksum ".ruby-version" }}-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
jobs:
build:
steps:
- <<: *restore_bundle_cache
- <<: *bundle_install
- <<: *save_bundle_cache
Use:
executors:
default:
working_directory: ~/repo
description: The official CircleCI Ruby Docker image
docker:
- image: circleci/ruby:2.6.1-node-browsers
Instead:
default: &default
working_directory: ~/repo
description: The official CircleCI Ruby Docker image
docker:
- image: circleci/ruby:2.6.1-node-browsers