Pipeline is full set of processes when we trigger work on projects
workflow:
build_test:
jobs:
- run_tests
- build
requires:
- run_tests
filters:
branches:
only: main
Jobs are the building blocks of config file. Jobs are a collection of steps, which run commands and scripts as required. All of the steps in the job are executed in a single unit which consumes a CircleCI container from your plan while it’s running.
Each job must declare an executor that is either docker, machine, windows or macos. machine includes a default image if not specified, for docker you must specify an image to use for the primary container, for macos you must specify an Xcode version, and for windows you must use the Windows orb.
.circleci/config.yml
file. This is where commands are executed for jobs using the Docker or machine executor. The Docker executor spins up a container with a Docker image. The machine executor spins up a complete Ubuntu virtual machine image. See Choosing an Executor Type document for a comparison table and considerations.version: 2.1
jobs:
one:
docker:
- image: circleci/ruby:2.4.1
steps:
- checkout
- run: echo "Hello Ruby"
- run: mkdir -p my_workspace
- run: echo "Trying out workspaces" > my_workspace/echo-output
- persist_to_workspace:
root: my_workspace
paths:
- echo-output
- run: sleep 25
two:
docker:
- image: circleci/ruby:2.4.1
steps:
- checkout
- run: echo "A more familiar Hi"
- attach_workspace:
at: my_workspace
- run: |
if [[ $(cat my_workspace/echo-output) == "Trying out workspaces" ]]; then
echo "It worked!";
else
echo "Nope!"; exit 1
fi
- run: sleep 15
workflows:
version: 2
one_two_wf:
jobs:
- one
- two:
requires:
- one
Parameters let you to reuse parts of your config code, witout repeating yourself. this ensures your config files are shorter, more readable, and easier to maintain.
Parameters work with jobs, commands, executors, as well as orbs.
You can use parameters within a single config file, and across config files.
version: 2.1
jobs:
build:
parameters:
p:
type: integer
default: 1
parallelism: << parameters.p >>
machine: true
steps:
- checkout
workflows:
workflow:
jobs:
- build:
p: 2
workflows:
my-workflow:
when: << pipeline.git.branch >>
steps:
- when:
condition:
and:
- << parameters.custom_checkout >>
- equal: [main, << paramters.git.brach >>]
steps:
version: 2.1
jobs:
test:
docker:
- image: cimg/node:<node-version>
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASS
steps:
- checkout
- restore_cache:
keys:
- node-deps-v1-{{ .Branch }}-{{checksum "package-lock.json"}}
- run:
name: install packages
command: npm ci
- save_cache:
key: node-deps-v1-{{ .Branch }}-{{checksum "package-lock.json"}}
paths:
- ~/.npm
- run:
name: Run Tests
command: npm run test
workflows:
test_my_app:
jobs:
- test
version: 2.1
orbs:
node: circleci/node@x.y
workflows:
test_my_app:
jobs:
- node/test:
version: <node-version>
version: 2.1
jobs:
build:
docker:
- image: circleci/node:14.17.3-buster-browsers
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASS
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run: docker build .