CircleCI is a continuous integration and continuous delivery platform that automates the build, test, and deployment of software.
.circleci/config.yml
file: Defines the CI/CD pipelineversion: 2.1
orbs:
node: circleci/node@5.0.2
workflows:
sample-workflow:
jobs:
- build-and-test
jobs:
build-and-test:
docker:
- image: cimg/node:18.1.0
steps:
- checkout
- node/install-packages:
pkg-manager: npm
- run:
name: Run tests
command: npm test
orbs:
node: circleci/node@5.0.2
orb.yml
circleci orb validate orb.yml
circleci orb publish orb.yml namespace/orb@dev:first
workflows:
version: 2
build-test-deploy:
jobs:
- build
- test:
requires:
- build
- deploy:
requires:
- test
filters:
branches:
only: main
workflows:
version: 2
build-test:
jobs:
- build
- test-1:
requires:
- build
- test-2:
requires:
- build
jobs:
build:
docker:
- image: cimg/base:stable
steps:
- checkout
- run:
name: Build application
command: make build
steps:
- run:
name: Run tests
command: |
if [ "${CIRCLE_BRANCH}" == "develop" ]; then
make test
fi
jobs:
build:
docker:
- image: cimg/node:18.1.0
jobs:
build:
machine:
image: ubuntu-2004:current
jobs:
build:
macos:
xcode: 14.2.0
CIRCLE_BRANCH
: The name of the Git branch currently being builtCIRCLE_SHA1
: The SHA1 hash of the last commit of the current buildCIRCLE_BUILD_NUM
: The number of the current buildCIRCLE_PROJECT_USERNAME
: The GitHub or Bitbucket username of the current projectCIRCLE_PROJECT_REPONAME
: The GitHub or Bitbucket repo name of the current projectSet in CircleCI UI: Project Settings > Environment Variables
steps:
- run:
name: Print custom variable
command: echo $MY_CUSTOM_VAR
steps:
- save_cache:
paths:
- ~/project/node_modules
key: npm-packages-{{ checksum "package-lock.json" }}
steps:
- restore_cache:
keys:
- npm-packages-{{ checksum "package-lock.json" }}
steps:
- store_artifacts:
path: test-results
destination: tr1
steps:
- store_test_results:
path: test-results
jobs:
build-and-push:
docker:
- image: cimg/base:stable
steps:
- checkout
- setup_remote_docker
- run:
name: Build and push Docker image
command: |
docker build -t myorg/myapp:$CIRCLE_SHA1 .
echo $DOCKER_PWD | docker login -u $DOCKER_LOGIN --password-stdin
docker push myorg/myapp:$CIRCLE_SHA1
jobs:
deploy-to-k8s:
docker:
- image: cimg/base:stable
steps:
- checkout
- kubernetes/create-or-update-resource:
resource-file: k8s/deployment.yml
resource-name: deployment/myapp
workflows:
version: 2
build-test-approve-deploy:
jobs:
- build
- test:
requires:
- build
- hold:
type: approval
requires:
- test
- deploy:
requires:
- hold
curl -X POST https://circleci.com/api/v2/project/:vcs-type/:org/:repo/pipeline -H "Circle-Token: $CIRCLE_TOKEN" -H "Content-Type: application/json" -d '{"branch":"main"}'
curl https://circleci.com/api/v2/project/:vcs-type/:org/:repo/pipeline -H "Circle-Token: $CIRCLE_TOKEN"
jobs:
build:
steps:
- run:
name: Enable SSH
command: |
mkdir -p ~/.ssh
echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==' >> ~/.ssh/known_hosts
- add_ssh_keys:
fingerprints:
- "SO:ME:FIN:G:ER:PR:IN:T"
Go to your project's build page > Artifacts tab
2024 © All rights reserved - buraxta.com