$npx -y skills add BagelHole/DevOps-Security-Agent-Skills --skill circleciConfigure CircleCI workflows and orbs for continuous integration and deployment. Create config.yml pipelines, use orbs for reusable configurations, and optimize build performance. Use when working with CircleCI for CI/CD automation.
| 1 | # CircleCI |
| 2 | |
| 3 | Build, test, and deploy applications using CircleCI's cloud-native CI/CD platform. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Setting up CI/CD pipelines with CircleCI |
| 9 | - Using orbs for reusable configuration |
| 10 | - Optimizing build times with caching and parallelism |
| 11 | - Configuring CircleCI workflows and approvals |
| 12 | - Managing CircleCI contexts and secrets |
| 13 | |
| 14 | ## Prerequisites |
| 15 | |
| 16 | - CircleCI account connected to repository |
| 17 | - Project enabled in CircleCI dashboard |
| 18 | - Basic YAML understanding |
| 19 | |
| 20 | ## Configuration File |
| 21 | |
| 22 | Create `.circleci/config.yml`: |
| 23 | |
| 24 | ```yaml |
| 25 | version: 2.1 |
| 26 | |
| 27 | orbs: |
| 28 | node: circleci/node@5.2 |
| 29 | docker: circleci/docker@2.4 |
| 30 | |
| 31 | executors: |
| 32 | default: |
| 33 | docker: |
| 34 | - image: cimg/node:20.10 |
| 35 | working_directory: ~/project |
| 36 | |
| 37 | jobs: |
| 38 | build: |
| 39 | executor: default |
| 40 | steps: |
| 41 | - checkout |
| 42 | - node/install-packages: |
| 43 | pkg-manager: npm |
| 44 | - run: |
| 45 | name: Build application |
| 46 | command: npm run build |
| 47 | - persist_to_workspace: |
| 48 | root: . |
| 49 | paths: |
| 50 | - dist |
| 51 | |
| 52 | test: |
| 53 | executor: default |
| 54 | steps: |
| 55 | - checkout |
| 56 | - node/install-packages: |
| 57 | pkg-manager: npm |
| 58 | - run: |
| 59 | name: Run tests |
| 60 | command: npm test |
| 61 | |
| 62 | deploy: |
| 63 | executor: default |
| 64 | steps: |
| 65 | - checkout |
| 66 | - attach_workspace: |
| 67 | at: . |
| 68 | - run: |
| 69 | name: Deploy |
| 70 | command: ./deploy.sh |
| 71 | |
| 72 | workflows: |
| 73 | build-test-deploy: |
| 74 | jobs: |
| 75 | - build |
| 76 | - test: |
| 77 | requires: |
| 78 | - build |
| 79 | - deploy: |
| 80 | requires: |
| 81 | - test |
| 82 | filters: |
| 83 | branches: |
| 84 | only: main |
| 85 | ``` |
| 86 | |
| 87 | ## Executors |
| 88 | |
| 89 | ### Docker Executor |
| 90 | |
| 91 | ```yaml |
| 92 | executors: |
| 93 | node: |
| 94 | docker: |
| 95 | - image: cimg/node:20.10 |
| 96 | - image: cimg/postgres:15.0 |
| 97 | environment: |
| 98 | POSTGRES_USER: test |
| 99 | POSTGRES_DB: testdb |
| 100 | working_directory: ~/app |
| 101 | ``` |
| 102 | |
| 103 | ### Machine Executor |
| 104 | |
| 105 | ```yaml |
| 106 | executors: |
| 107 | linux-machine: |
| 108 | machine: |
| 109 | image: ubuntu-2204:current |
| 110 | resource_class: large |
| 111 | ``` |
| 112 | |
| 113 | ### macOS Executor |
| 114 | |
| 115 | ```yaml |
| 116 | executors: |
| 117 | macos: |
| 118 | macos: |
| 119 | xcode: "15.0.0" |
| 120 | resource_class: macos.m1.medium.gen1 |
| 121 | ``` |
| 122 | |
| 123 | ## Caching |
| 124 | |
| 125 | ### Dependency Caching |
| 126 | |
| 127 | ```yaml |
| 128 | jobs: |
| 129 | build: |
| 130 | steps: |
| 131 | - checkout |
| 132 | - restore_cache: |
| 133 | keys: |
| 134 | - v1-deps-{{ checksum "package-lock.json" }} |
| 135 | - v1-deps- |
| 136 | - run: npm ci |
| 137 | - save_cache: |
| 138 | key: v1-deps-{{ checksum "package-lock.json" }} |
| 139 | paths: |
| 140 | - node_modules |
| 141 | ``` |
| 142 | |
| 143 | ### Multi-Key Caching |
| 144 | |
| 145 | ```yaml |
| 146 | - restore_cache: |
| 147 | keys: |
| 148 | - v1-{{ .Branch }}-{{ checksum "package-lock.json" }} |
| 149 | - v1-{{ .Branch }}- |
| 150 | - v1-main- |
| 151 | - v1- |
| 152 | ``` |
| 153 | |
| 154 | ## Workspaces |
| 155 | |
| 156 | ### Persist Data |
| 157 | |
| 158 | ```yaml |
| 159 | jobs: |
| 160 | build: |
| 161 | steps: |
| 162 | - checkout |
| 163 | - run: npm run build |
| 164 | - persist_to_workspace: |
| 165 | root: . |
| 166 | paths: |
| 167 | - dist |
| 168 | - node_modules |
| 169 | |
| 170 | deploy: |
| 171 | steps: |
| 172 | - attach_workspace: |
| 173 | at: ~/project |
| 174 | - run: ./deploy.sh |
| 175 | ``` |
| 176 | |
| 177 | ## Parallelism |
| 178 | |
| 179 | ### Test Splitting |
| 180 | |
| 181 | ```yaml |
| 182 | jobs: |
| 183 | test: |
| 184 | parallelism: 4 |
| 185 | steps: |
| 186 | - checkout |
| 187 | - run: |
| 188 | name: Run tests |
| 189 | command: | |
| 190 | TESTFILES=$(circleci tests glob "test/**/*.test.js" | circleci tests split --split-by=timings) |
| 191 | npm test -- $TESTFILES |
| 192 | - store_test_results: |
| 193 | path: test-results |
| 194 | ``` |
| 195 | |
| 196 | ## Workflows |
| 197 | |
| 198 | ### Sequential Jobs |
| 199 | |
| 200 | ```yaml |
| 201 | workflows: |
| 202 | pipeline: |
| 203 | jobs: |
| 204 | - build |
| 205 | - test: |
| 206 | requires: |
| 207 | - build |
| 208 | - deploy: |
| 209 | requires: |
| 210 | - test |
| 211 | ``` |
| 212 | |
| 213 | ### Parallel Jobs |
| 214 | |
| 215 | ```yaml |
| 216 | workflows: |
| 217 | pipeline: |
| 218 | jobs: |
| 219 | - build |
| 220 | - test-unit: |
| 221 | requires: |
| 222 | - build |
| 223 | - test-integration: |
| 224 | requires: |
| 225 | - build |
| 226 | - deploy: |
| 227 | requires: |
| 228 | - test-unit |
| 229 | - test-integration |
| 230 | ``` |
| 231 | |
| 232 | ### Manual Approval |
| 233 | |
| 234 | ```yaml |
| 235 | workflows: |
| 236 | deploy-prod: |
| 237 | jobs: |
| 238 | - build |
| 239 | - test |
| 240 | - hold: |
| 241 | type: approval |
| 242 | requires: |
| 243 | - test |
| 244 | - deploy-production: |
| 245 | requires: |
| 246 | - hold |
| 247 | ``` |
| 248 | |
| 249 | ### Scheduled Workflows |
| 250 | |
| 251 | ```yaml |
| 252 | workflows: |
| 253 | nightly: |
| 254 | triggers: |
| 255 | - schedule: |
| 256 | cron: "0 2 * * *" |
| 257 | filters: |
| 258 | branches: |
| 259 | only: |
| 260 | - main |
| 261 | jobs: |
| 262 | - build |
| 263 | - test |
| 264 | ``` |
| 265 | |
| 266 | ### Branch Filtering |
| 267 | |
| 268 | ```yaml |
| 269 | workflows: |
| 270 | build-deploy: |
| 271 | jobs: |
| 272 | - build: |
| 273 | filters: |
| 274 | branches: |
| 275 | only: |
| 276 | - main |
| 277 | - /feature-.*/ |
| 278 | - deploy: |
| 279 | filters: |
| 280 | branches: |
| 281 | only: main |
| 282 | tags: |
| 283 | only: /^v.*/ |
| 284 | ``` |