circleci-docs.txt 139 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248
  1. 0
  2. 1
  3. 2
  4. 3
  5. 4
  6. 8
  7. 15
  8. 16
  9. 20
  10. 24
  11. 30
  12. 32
  13. 60
  14. 150
  15. 200
  16. Docs
  17. Go to Application
  18. CircleCI.comAcademyBlogCommunitySupport
  19. About CircleCI icon
  20. About CircleCI
  21. Getting started icon
  22. Getting started
  23. First steps
  24. Sign up and try
  25. Join teammates on CircleCI
  26. Create a project
  27. Quickstart guide
  28. Hello world
  29. YAML configuration intro
  30. In-app configuration editor
  31. Migration
  32. Introduction to CircleCI migration
  33. Migrate from AWS
  34. Migrate from Azure DevOps
  35. Migrate from Buildkite
  36. Migrate from GitHub Actions
  37. Migrate from GitLab
  38. Migrate from Jenkins
  39. Migrate from TeamCity
  40. Migrate from Travis CI
  41. Tutorials
  42. Node quickstart
  43. Python quickstart
  44. Go quickstart
  45. Configuration tutorial
  46. Use the Slack orb to set up notifications
  47. Reference
  48. Configuration reference
  49. FAQ
  50. Reference icon
  51. Concepts
  52. Reusable configuration reference
  53. Project values and variables
  54. API v2 reference
  55. API v1 reference
  56. Self-hosted runner API
  57. Optimization reference
  58. Insights metrics glossary
  59. Config policy reference
  60. Webhooks reference
  61. Frequently asked questions
  62. Troubleshoot
  63. Orchestrate and trigger icon
  64. Orchestrate and trigger
  65. Execute jobs on managed compute resources icon
  66. Execute jobs on managed compute resources
  67. Execute jobs on self-hosted runners icon
  68. Execute jobs on self-hosted runners
  69. Test icon
  70. Test
  71. Deploy icon
  72. Deploy
  73. Release icon
  74. Release
  75. Optimize icon
  76. Optimize
  77. Project Insights icon
  78. Project Insights
  79. Package and re-use config with orbs icon
  80. Package and re-use config with orbs
  81. Manage roles, permissions, and authentication icon
  82. Manage roles, permissions, and authentication
  83. Manage security and secrets icon
  84. Manage security and secrets
  85. Manage config policies icon
  86. Manage config policies
  87. Integration icon
  88. Integration
  89. Developer toolkit icon
  90. Developer toolkit
  91. Server administration v4.7 icon
  92. Server administration v4.7
  93. Server administration v4.6 icon
  94. Server administration v4.6
  95. Server administration v4.5 icon
  96. Server administration v4.5
  97. Server administration v4.4 icon
  98. Server administration v4.4
  99. Server administration v4.3 icon
  100. Server administration v4.3
  101. Server administration v4.2 icon
  102. Server administration v4.2
  103. Server administration v4.1 icon
  104. Server administration v4.1
  105. Plans and pricing icon
  106. Plans and pricing
  107. Contributing to CircleCI docs icon
  108. Contributing to CircleCI docs
  109. 2 days ago
  110. Cloud
  111. Server v4.x
  112. Server v3.x
  113. Helpful Resources
  114. 6 config optimization tips
  115. Intro to dynamic config
  116. Using dynamic config
  117. Validate your config using local CLI
  118. How to trigger a single job
  119. On This Page
  120. version
  121. setup
  122. orbs
  123. commands
  124. parameters
  125. executors
  126. jobs
  127. <job_name>
  128. type
  129. environment
  130. parallelism
  131. Executor docker / machine / macos
  132. docker
  133. Docker registry authentication
  134. AWS authentication
  135. Use OIDC
  136. Use environment variables
  137. machine
  138. Available Linux machine images
  139. Available Linux machine images on server
  140. Available Linux GPU machine images
  141. Available Android machine images
  142. Available Windows machine images
  143. Available Windows machine images on server
  144. Available Windows GPU machine image
  145. macos
  146. branches - DEPRECATED
  147. resource_class
  148. Self-hosted runner
  149. Docker execution environment
  150. x86
  151. Arm
  152. LinuxVM execution environment
  153. macOS execution environment
  154. macOS execution environment on server
  155. Windows execution environment
  156. GPU execution environment (Linux)
  157. GPU execution-environment (Windows)
  158. Arm VM execution-environment
  159. steps
  160. run
  161. Default shell options
  162. Background commands
  163. Shorthand syntax
  164. The when attribute
  165. Ending a job from within a step
  166. The when step
  167. checkout
  168. setup_remote_docker
  169. save_cache
  170. restore_cache
  171. deploy - DEPRECATED
  172. store_artifacts
  173. store_test_results
  174. persist_to_workspace
  175. attach_workspace
  176. add_ssh_keys
  177. Using pipeline values
  178. circleci_ip_ranges
  179. workflows
  180. <workflow_name>
  181. triggers
  182. schedule
  183. cron
  184. filters
  185. branches
  186. Using when in workflows
  187. requires
  188. name
  189. context
  190. Expression-based job filters
  191. tags
  192. matrix
  193. Excluding sets of parameters from a matrix
  194. Dependencies and matrix jobs
  195. pre-steps and post-steps
  196. Logic statements
  197. Logic statement examples
  198. Example full configuration
  199. This document is a reference for the CircleCI 2.x configuration keys that are used in the .circleci/config.yml file.
  200. You can see a complete config.yml in our full example.
  201. Key Required Type Description
  202. Y
  203. String
  204. 2, 2.0, or 2.1 See the Reusable configuration page for an overview of 2.1 keys available to simplify your .circleci/config.yml file, reuse, and parameterized jobs.
  205. The version field is intended to be used in order to issue warnings for deprecation or breaking changes.
  206. N
  207. Boolean
  208. Designates the config.yaml for use of CircleCI’s dynamic configuration feature.
  209. The setup field enables you to conditionally trigger configurations from outside the primary .circleci parent directory, update pipeline parameters, or generate customized configurations.
  210. The orbs key is supported in version: 2.1 configuration
  211. Map
  212. A map of user-selected names to either: orb references (strings) or orb definitions (maps). Orb definitions must be the orb-relevant subset of 2.1 config. See the Creating Orbs documentation for details.
  213. A map of strings to executor definitions. See the
  214. section below.
  215. A map of command names to command definitions. See the
  216. The following example uses the node orb that exists in the certified circleci namespace. Refer to the Node orb page in the Orb Registry for more examples and information.
  217. version: 2.1
  218. orbs:
  219. node: circleci/node@x.y
  220. jobs:
  221. install-node-example:
  222. docker:
  223. - image: cimg/base:stable
  224. steps:
  225. - checkout
  226. - node/install:
  227. install-yarn: true
  228. node-version: '16.13'
  229. - run: node --version
  230. workflows:
  231. test_my_app:
  232. - install-node-example
  233. Documentation is available for orbs in the following sections:
  234. Using Orbs
  235. Authoring Orbs.
  236. Public orbs are listed in the Orb Registry.
  237. The commands key is supported in version: 2.1 configuration
  238. A command 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. For more information see the Reusable Config Reference Guide.
  239. Sequence
  240. A sequence of steps run inside the calling job of the command.
  241. A map of parameter keys. See the Parameter Syntax section of the Reusing Config document for details.
  242. description
  243. A string that describes the purpose of the command.
  244. Example:
  245. commands:
  246. sayhello:
  247. description: "A very simple command for demonstration purposes"
  248. parameters:
  249. to:
  250. type: string
  251. default: "Hello World"
  252. - run: echo << parameters.to >>
  253. The pipeline parameters key is supported in version: 2.1 configuration
  254. Pipeline parameters declared for use in the configuration. See Pipeline Values and Parameters for usage details.
  255. A map of parameter keys. Supports string, boolean, integer and enum types. See Parameter Syntax for details.
  256. The executors key is supported in version: 2.1 configuration
  257. Executors define the execution environment in which the steps of a job will be run, allowing you to reuse a single executor definition across multiple jobs.
  258. Y (1)
  259. List
  260. Options for Docker executor
  261. Amount of CPU and RAM allocated to each container in a job.
  262. Options for machine executor
  263. Options for macOS executor
  264. windows
  265. Windows executor currently working with orbs. Check out the orb.
  266. shell
  267. Shell to use for execution command in all steps. Can be overridden by shell in each step (default: See Default Shell Options)
  268. working_directory
  269. In which directory to run the steps. Will be interpreted as an absolute path.
  270. A map of environment variable names and values.
  271. (1) One executor type should be specified per job. If more than one is set you will receive an error.
  272. executors:
  273. my-executor:
  274. - image: cimg/ruby:3.0.3-browsers
  275. my-job:
  276. executor: my-executor
  277. - run: echo "Hello executor!"
  278. See the Using Parameters in Executors section of the Reusing config page for examples of parameterized executors.
  279. A Workflow is comprised of one or more uniquely named jobs. Jobs are specified in the jobs map, see Sample config.yml for two examples of a job map. The name of the job is the key in the map, and the value is a map describing the job.
  280. Jobs have a maximum runtime of 1 (Free), 3 (Performance), or 5 (Scale) hours depending on pricing plan. If your jobs are timing out, consider a larger
  281. and/or parallelism. Additionally, you can upgrade your pricing plan or run some of your jobs concurrently using workflows.
  282. Each job consists of the job’s name as a key and a map as a value. A name should be case insensitive unique within a current jobs list. The value map has the following attributes:
  283. Job type, can be build, release or approval. If not specified, defaults to build.
  284. Options for the Docker executor
  285. Options for the machine executor
  286. Options for the macOS executor
  287. Parameters for making a job explicitly configurable in a workflow.
  288. A list of steps to be performed
  289. In which directory to run the steps. Will be interpreted as an absolute path. Default: ~/project (where project is a literal string, not the name of your specific project). Processes run during the job can use the $CIRCLE_WORKING_DIRECTORY environment variable to refer to this directory. Note: Paths written in your YAML configuration file will not be expanded; if your store_test_results.path is $CIRCLE_WORKING_DIRECTORY/tests, then CircleCI will attempt to store the test subdirectory of the directory literally named $CIRCLE_WORKING_DIRECTORY, dollar sign $ and all. working_directory will be created automatically if it doesn’t exist.
  290. Integer
  291. Number of parallel instances of this job to run (default: 1)
  292. This key is deprecated. Use workflows filtering to control which jobs run for which branches.
  293. Configure a job type. Options are release, approval, build (default). If a type is not specified, the job defaults to a build type.
  294. Jobs with the release type are used to connect your pipeline configuration to a release in the CircleCI releases UI. For full details, see the Releases overview page.
  295. The approval type is used to configure a manual approval step. No job configuration is required or allowed for an approval type job. The approval type is most commonly configured within a workflow rather than under the top-level jobs key. Only approval type jobs can have their type configured under workflows. See type under workflows section for full details.
  296. A map of environment variable names and values. For more information on defining and using environment variables, and the order of precedence governing the various ways they can be set, see the Environment variables page.
  297. This feature is used to optimize test steps. If parallelism is set to N > 1, then N independent executors will be set up and each will run the steps of that job in parallel.
  298. You can use the CircleCI CLI to split your test suite across parallel containers so the job completes in a shorter time.
  299. Read more about splitting tests across parallel execution environments on the Parallelism and test splitting page.
  300. Refer to the Use the CircleCI CLI to split tests how-to guide.
  301. Follow the Test splitting tutorial.
  302. build:
  303. - image: cimg/base:2022.09
  304. environment:
  305. FOO: bar
  306. parallelism: 3
  307. resource_class: large
  308. working_directory: ~/my-app
  309. - run: go list ./... | circleci tests run --command "xargs gotestsum --junitfile junit.xml --format testname --" --split-by=timings --timings-type=name
  310. Job-level parameters can be used when calling a
  311. job
  312. in a
  313. workflow
  314. .
  315. Reserved parameter-names:
  316. See Parameter Syntax for definition details.
  317. CircleCI offers several execution environments in which to run your jobs. To specify an execution environment choose an executor, then specify and image and a resource class. An executor defines the underlying technology, environment, and operating system in which to run a job.
  318. Set up your jobs to run using the docker (Linux), machine (LinuxVM, Windows, GPU, Arm), or macos executor, then specify an image with the tools and packages you need, and a resource class.
  319. Learn more about execution environments and executors in the Introduction to Execution Environments.
  320. Configured by docker key which takes a list of maps:
  321. image
  322. The name of a custom Docker image to use. The first image listed under a job defines the job’s own primary container image where all steps will run.
  323. name defines the hostname for the container (the default is localhost), which is used for reaching secondary (service) containers. By default, all services are exposed directly on localhost. This field is useful if you would rather have a different hostname instead of localhost, for example, if you are starting multiple versions of the same service.
  324. entrypoint
  325. String or List
  326. The command used as executable when launching the container. entrypoint overrides the image’s
  327. ENTRYPOINT
  328. command
  329. The command used as PID 1 (or arguments for entrypoint) when launching the container. command overrides the image’s COMMAND. It will be used as arguments to the image ENTRYPOINT if it has one, or as the executable if the image has no ENTRYPOINT.
  330. user
  331. Which user to run commands as within the Docker container
  332. A map of environment variable names and values. The environment settings apply to the entrypoint/command run by the Docker container, not the job steps.
  333. auth
  334. Authentication for registries using standard docker login credentials
  335. aws_auth
  336. Authentication for AWS Elastic Container Registry (ECR)
  337. For a primary container, (the first container in the list) if neither command nor entrypoint is specified in the configuration, then any ENTRYPOINT and COMMAND in the image are ignored. This is because the primary container is typically only used for running the steps and not for its ENTRYPOINT, and an ENTRYPOINT may consume significant resources or exit prematurely. A custom image may disable this behavior and force the ENTRYPOINT to run.
  338. You can specify image versions using tags or digest. You can use any public images from any public Docker registry (defaults to Docker Hub). Learn more about specifying images on the Using the Docker Execution Environment page.
  339. Some registries, Docker Hub, for example, may rate limit anonymous Docker pulls. We recommend that you authenticate to pull private and public images. The username and password can be specified in the auth field. See Using Docker Authenticated Pulls for details.
  340. - image: buildpack-deps:trusty # primary container
  341. auth:
  342. username: mydockerhub-user
  343. password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
  344. ENV: CI
  345. - image: mongo:2.6.8
  346. command: [--smallfiles]
  347. - image: postgres:14.2
  348. POSTGRES_USER: user
  349. - image: redis@sha256:54057dd7e125ca41afe526a877e8bd35ec2cdd33b9217e022ed37bdcf7d09673
  350. - image: acme-private/private-image:321
  351. Using an image hosted on AWS ECR
  352. requires authentication using AWS credentials.
  353. Authenticate using OpenID Connect (OIDC) using the oidc_role_arn field, as follows:
  354. job_name:
  355. - image: <your-image-arn>
  356. aws_auth:
  357. oidc_role_arn: <your-iam-role-arn>
  358. For steps to get set up with OIDC to pull images from AWS ECR, see the Pull and image from AWS ECR with OIDC page.
  359. By default, CircleCI uses the AWS credentials you provide by setting the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY project environment variables. It is also possible to set the credentials by using the aws_auth field as in the following example:
  360. - image: account-id.dkr.ecr.us-east-1.amazonaws.com/org/repo:0.1
  361. aws_access_key_id: AKIAQWERVA # can specify string literal values
  362. aws_secret_access_key: $ECR_AWS_SECRET_ACCESS_KEY # or project UI envar reference
  363. CircleCI cloud The use of machine: true is deprecated. You must specify an image to use.
  364. The machine executor is configured using the machine key, which takes a map:
  365. The virtual machine image to use. View available images. Note: This key is not supported for Linux VMs on installations of CircleCI server. For information about customizing machine executor images on CircleCI installed on your servers, see our Machine provisioner documentation.
  366. docker_layer_caching
  367. Set this to true to enable Docker layer caching.
  368. build: # name of your job
  369. machine: # executor type
  370. image: ubuntu-2004:current # recommended linux image - includes Ubuntu 20.04, docker 19.03.13, docker-compose 1.27.4
  371. # Commands run in a Linux virtual machine environment
  372. Specifying an image in your configuration file is strongly recommended. CircleCI supports multiple Linux machine images that can be specified in the image field. For a full list of supported image tags, refer to the following pages in the Developer Hub:
  373. Ubuntu-2004
  374. Ubuntu-2204
  375. More information on the software available in each image can be found in our Discuss forum
  376. The machine executor supports Docker Layer Caching, which is useful when you are building Docker images during your job or Workflow.
  377. If you are using CircleCI server, contact your system administrator for details of available Linux machine images.
  378. When using the Linux GPU executor, the available images are:
  379. linux-cuda-11:default v11.4, v11.6, v11.8 (default), Docker v20.10.24
  380. linux-cuda-12:default v12.0, v12.1 (default), Docker v20.10.24
  381. CircleCI supports running jobs on Android for testing and deploying Android applications.
  382. To use the Android image directly with the machine executor, add the following to your job:
  383. machine:
  384. image: android:2022.09.1
  385. The Android image can also be accessed using the Android orb.
  386. For examples, refer to the Using Android Images with the Machine Executor page.
  387. Specifying an image in your configuration file is strongly recommended. CircleCI supports multiple Windows machine images that can be specified in the image field.
  388. For a full list of supported images, refer to one of the following:
  389. windows-server-2022-gui
  390. windows-server-2019
  391. More information on what software is available in each image can be found in our Discuss forum
  392. Alternatively, use the Windows orb to manage your Windows execution environment. For examples, see the Using the Windows Execution Environment page.
  393. If you are using CircleCI server, contact your system administrator for details of available Windows machine images.
  394. When using the Windows GPU executor, the available image is:
  395. windows-server-2019-cuda
  396. Example
  397. image: windows-server-2019-cuda:current
  398. CircleCI supports running jobs on macOS
  399. , to allow you to build, test, and deploy apps for macOS, iOS
  400. , tvOS
  401. and watchOS
  402. . To run a job in a macOS virtual machine, add the macos key to the top-level configuration for your job and specify the version of Xcode you would like to use.
  403. xcode
  404. The version of Xcode that is installed on the virtual machine, see the Supported Xcode Versions section of the Testing iOS document for the complete list.
  405. Example: Use a macOS virtual machine with Xcode version 14.2.0:
  406. macos:
  407. xcode: "14.2.0"
  408. The resource_class feature allows you to configure CPU and RAM resources for each job. Resource classes are available for each execution environment, as described in the tables below.
  409. We implement soft concurrency limits for each resource class to ensure our system remains stable for all customers. If you are on a Performance or Custom Plan and experience queuing for certain resource classes, it is possible you are hitting these limits. Contact CircleCI support
  410. to request a raise on these limits for your account.
  411. If you do not specify a resource class, CircleCI will use a default value that is subject to change. It is best practice to specify a resource class as opposed to relying on a default.
  412. Java, Erlang and any other languages that introspect the /proc directory for information about CPU count may require additional configuration to prevent them from slowing down when using the CircleCI resource class feature. Programs with this issue may request 32 CPU cores and run slower than they would when requesting one core. Users of languages with this issue should pin their CPU count to their guaranteed CPU resources.
  413. If you want to confirm how much memory you have been allocated, you can check the cgroup memory hierarchy limit with grep hierarchical_memory_limit /sys/fs/cgroup/memory/memory.stat.
  414. Use the resource_class key to configure a self-hosted runner instance.
  415. For example:
  416. machine: true
  417. resource_class: <my-namespace>/<my-runner>
  418. resource_class: xlarge
  419. ... // other config
  420. For credit and access information, see the Resource classes page. Resource class access is dependent on your Plan.
  421. Class vCPUs RAM Cloud Server
  422. small
  423. 2GB
  424. medium
  425. 4GB
  426. medium+
  427. 6GB
  428. large
  429. 8GB
  430. xlarge
  431. 16GB
  432. 2xlarge
  433. 32GB
  434. 2xlarge+
  435. 40GB
  436. Arm on Docker For pricing information, and a list of CircleCI Docker convenience images that support Arm resource classes, see the Resource classes page.
  437. Arm on Docker For credit and access information see the Resource classes page. Resource class access is dependent on your Plan
  438. To find out which CircleCI Docker convenience images support Arm resource classes, you can refer to Docker hub
  439. :
  440. Select the image (for example, cimg/python).
  441. Select the tags tab.
  442. View what is supported under OS/ARCH for the latest tags. For example, cimg/python has linux/amd64 and linux/arm64, which means Arm is supported.
  443. arm.medium
  444. 8 GB
  445. arm.large
  446. 16 GB
  447. arm.xlarge
  448. 32 GB
  449. arm.2xlarge
  450. 64 GB
  451. Class vCPUs RAM Disk Size Cloud Server
  452. 7.5 GB
  453. 150GB
  454. 15 GB
  455. image: ubuntu-2004:202010-01 # recommended linux image
  456. macos.m1.medium.gen1
  457. 4 @ 3.2 GHz
  458. macos.m1.large.gen1
  459. 8 @ 3.2 GHz
  460. 12GB
  461. m2pro.medium
  462. 4 @ 3.49 GHz
  463. m2pro.large
  464. 8 @ 3.49 GHz
  465. We have deprecated support for all Intel-based macOS resources.
  466. The macos.x86.medium.gen2 resource class was deprecated on June 28, 2024.
  467. See our announcement
  468. for more details.
  469. xcode: "15.4.0"
  470. resource_class: m2pro.medium
  471. If you are working on CircleCI server v3.1 and up, you can access the macOS execution environment using self-hosted runner.
  472. windows.medium (default)
  473. 15GB
  474. 200 GB
  475. windows.large
  476. 30GB
  477. windows.xlarge
  478. 60GB
  479. windows.2xlarge
  480. 128GB
  481. Using server? Check with your systems administrator whether you have access to the Windows execution environment.
  482. resource_class: 'windows.medium'
  483. image: 'windows-server-2022-gui:current'
  484. shell: 'powershell.exe -ExecutionPolicy Bypass'
  485. # Commands are run in a Windows virtual machine environment
  486. - run: Write-Host 'Hello, Windows'
  487. Class vCPUs RAM GPUs GPU model GPU Memory (GiB) Disk Size (GiB) Cloud Server
  488. gpu.nvidia.small
  489. NVIDIA Tesla P4
  490. gpu.nvidia.small.gen2
  491. NVIDIA A10G
  492. gpu.nvidia.small.multi
  493. NVIDIA Tesla T4
  494. gpu.nvidia.medium.multi
  495. gpu.nvidia.medium
  496. gpu.nvidia.large
  497. NVIDIA Tesla V100
  498. image: linux-cuda-12:default
  499. resource_class: gpu.nvidia.medium
  500. - run: nvidia-smi
  501. - run: docker run --gpus all nvidia/cuda:9.0-base nvidia-smi
  502. See the Available Linux GPU images section for the full list of available images.
  503. windows.gpu.nvidia.medium
  504. win: circleci/windows@5.0.0
  505. executor: win/server-2019-cuda
  506. - run: '&"C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe"'
  507. (2) This resource requires review by our support team. Open a support ticket
  508. if you would like to request access.
  509. arm.medium (default)
  510. 100 GB
  511. 64GB
  512. Using server? Check with your systems administrator whether you have access to the Arm execution environment.
  513. image: ubuntu-2004:202101-01
  514. resource_class: arm.medium
  515. - run: uname -a
  516. - run: echo "Hello, Arm!"
  517. The steps setting in a job should be a list of single key/value pairs, the key of which indicates the step type. The value may be either a configuration map or a string (depending on what that type of step requires). For example, using a map:
  518. working_directory: ~/canary-python
  519. - run:
  520. name: Running tests
  521. command: make test
  522. Here run is a step type. The name attribute is used by the UI for display purposes. The command attribute is specific for run step and defines command to execute.
  523. Some steps may implement a shorthand semantic. For example, run may be also be called like this:
  524. - run: make test
  525. In its short form, the run step allows us to directly specify which command to execute as a string value. In this case step itself provides default suitable values for other attributes (name here will have the same value as command, for example).
  526. Another shorthand, which is possible for some steps, is to use the step name as a string instead of a key/value pair:
  527. In this case, the checkout step will check out project source code into the job’s
  528. In general all steps can be described as:
  529. <step_type>
  530. Map or String
  531. A configuration map for the step or some string whose semantics are defined by the step.
  532. Each built-in step is described in detail below.
  533. Used for invoking all command-line programs, taking either a map of configuration values, or, when called in its short-form, a string that will be used as both the command and name. Run commands are executed using non-login shells by default, so you must explicitly source any dotfiles as part of the command.
  534. the run step replaces the deprecated deploy step. If your job has a parallelism of 1, the deprecated deploy step can be swapped out directly for the run step. If your job has parallelism > 1, see Migrate from deploy to run.
  535. Command to run via the shell
  536. Title of the step to be shown in the CircleCI UI (default: full command)
  537. Shell to use for execution command (default: See Default Shell Options)
  538. Additional environmental variables, locally scoped to command
  539. background
  540. Whether or not this step should run in the background (default: false)
  541. In which directory to run this step. Will be interpreted relative to the
  542. of the job). (default: .)
  543. no_output_timeout
  544. Elapsed time the command can run without output. The string is a decimal with unit suffix, such as "20m", "1.25h", "5s". The default is 10 minutes and the maximum is governed by the maximum time a job is allowed to run.
  545. when
  546. Specify when to enable or disable the step. Takes the following values: always, on_success, on_fail (default: on_success)
  547. Each run declaration represents a new shell. It is possible to specify a multi-line command, each line of which will be run in the same shell:
  548. command: |
  549. echo Running test
  550. mkdir -p /tmp/test-results
  551. make test
  552. You can also configure commands to run in the background if you do not want to wait for the step to complete before moving on to subsequent run steps.
  553. For jobs that run on Linux, the default value of the shell option is /bin/bash -eo pipefail if /bin/bash is present in the build container. Otherwise it is /bin/sh -eo pipefail. The default shell is not a login shell (--login or -l are not specified). Hence, the shell will not source your ~/.bash_profile, ~/.bash_login, ~/.profile files.
  554. For jobs that run on macOS, the default shell is /bin/bash --login -eo pipefail. The shell is a non-interactive login shell. The shell will execute /etc/profile/ followed by ~/.bash_profile before every step.
  555. For more information about which files are executed when Bash is invocated, see the
  556. INVOCATION
  557. section of the
  558. bash
  559. manpage
  560. Descriptions of the -eo pipefail options are provided below.
  561. -e
  562. Exit immediately if a pipeline (which may consist of a single simple command), a subshell command enclosed in parentheses, or one of the commands executed as part of a command list enclosed by braces exits with a non-zero status.
  563. So if in the previous example mkdir failed to create a directory and returned a non-zero status, then command execution would be terminated, and the whole step would be marked as failed. If you desire the opposite behaviour, you need to add set +e in your command or override the default shell in your configuration map of run. For example:
  564. set +e
  565. shell: /bin/sh
  566. -o pipefail
  567. If pipefail is enabled, the pipeline’s return status is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands exit successfully. The shell waits for all commands in the pipeline to terminate before returning a value.
  568. - run: make test | tee test-output.log
  569. If make test fails, the -o pipefail option will cause the whole step to fail. Without -o pipefail, the step will always run successfully because the result of the whole pipeline is determined by the last command (tee test-output.log), which will always return a zero status.
  570. If make test fails the rest of pipeline will be executed.
  571. If you want to avoid this behaviour, you can specify set +o pipefail in the command or override the whole shell (see example above).
  572. In general, we recommend using the default options (-eo pipefail) because they show errors in intermediate commands and simplify debugging job failures. For convenience, the UI displays the used shell and all active options for each run step.
  573. For more information, see the Using Shell Scripts document.
  574. The background attribute enables you to configure commands to run in the background. Job execution will immediately proceed to the next step rather than waiting for return of a command with the background attribute set to true. The following example shows the configuration for running the X virtual framebuffer in the background which is commonly required to run Selenium tests:
  575. name: Running X virtual framebuffer
  576. command: Xvfb :99 -screen 0 1280x1024x24
  577. background: true
  578. run has a very convenient shorthand syntax:
  579. # shorthanded command can also have multiple lines
  580. - run: |
  581. In this case, command and name become the string value of run, and the rest of the config map for that run have their default values.
  582. By default, CircleCI will execute job steps one at a time, in the order that they are defined in config.yml, until a step fails (returns a non-zero exit code). After a command fails, no further job steps will be executed.
  583. Adding the when attribute to a job step allows you to override this default behaviour, and selectively run or skip steps depending on the status of the job.
  584. The default value of on_success means that the step will run only if all of the previous steps have been successful (returned exit code 0).
  585. A value of always means that the step will run regardless of the exit status of previous steps. This is useful if you have a task that you want to run regardless of whether the previous steps are successful or not. For example, you might have a job step that needs to upload logs or code-coverage data somewhere.
  586. A value of on_fail means that the step will run only if one of the preceding steps has failed (returns a non-zero exit code). It is common to use on_fail if you want to store some diagnostic data to help debug test failures, or to run custom notifications about the failure, such as sending emails or triggering alerts.
  587. Some steps, such as store_artifacts and store_test_results will always run, even if a step has failed (returned a non-zero exit code) previously. The when attribute, store_artifacts and store_test_results are not run if the job has been killed by a cancel request or has reached the runtime timeout limit.
  588. name: Upload CodeCov.io Data
  589. command: bash <(curl -s https://codecov.io/bash) -F unittests
  590. when: always # Uploads code coverage results, pass or fail
  591. A job can exit without failing by using run: circleci-agent step halt. However, if a step within the job is already failing then the job will continue to fail. This can be useful in situations where jobs need to conditionally execute.
  592. Here is an example where halt is used to avoid running a job on the develop branch:
  593. run: |
  594. if [ "$CIRCLE_BRANCH" = "develop" ]; then
  595. circleci-agent step halt
  596. fi
  597. The when and unless steps are supported in version: 2.1 configuration
  598. 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 reusable configuration reference for more details.
  599. condition
  600. Logic
  601. A logic statement
  602. A list of steps to execute when the condition is true
  603. jobs: # conditional steps may also be defined in `commands:`
  604. job_with_optional_custom_checkout:
  605. custom_checkout:
  606. default: ""
  607. image: ubuntu-2004:202107-02
  608. - when:
  609. condition: <<parameters.custom_checkout>>
  610. - run: echo "my custom checkout"
  611. - unless:
  612. build-test-deploy:
  613. - job_with_optional_custom_checkout:
  614. custom_checkout: "any non-empty string is truthy"
  615. - job_with_optional_custom_checkout
  616. Blobless clones
  617. To help improve the overall performance of code checkouts from Git source code hosts, a "blobless" strategy is being rolled out. This reduces the amount of data fetched from the remote, by asking the remote to filter out objects that are not attached to the current commit.
  618. While this improves performance in most cases, if a downstream step requires those objects to exist for scanning or comparisons, it can cause failures. To work around these potential problems, a fetch directly after a checkout will ensure the required data is available:
  619. - run: git fetch
  620. A special step used to check out source code to the configured path (defaults to the working_directory). The reason this is a special step is because it is more of a helper function designed to simplify the process of checking out code. If you require doing git over HTTPS you should not use this step as it configures git to checkout over SSH.
  621. path
  622. Checkout directory. Will be interpreted relative to the
  623. If path already exists and is:
  624. A git repository - step will not clone whole repository, instead will fetch origin
  625. NOT a git repository - step will fail.
  626. In the case of checkout, the step type is just a string with no additional attributes:
  627. The checkout command automatically adds the required authenticity keys for interacting with GitHub and Bitbucket over SSH, which is detailed further in our integration guide — this guide will also be helpful if you wish to implement a custom checkout command.
  628. CircleCI does not check out submodules. If your project requires submodules, add run steps with appropriate commands as shown in the following example:
  629. - run: git submodule sync
  630. - run: git submodule update --init
  631. The checkout step will configure Git to skip automatic garbage collection. If you are caching your .git directory with
  632. and would like to use garbage collection to reduce its size, you may wish to use a
  633. step with command git gc before doing so.
  634. Allows Docker commands to be run locally. See Running Docker commands for details.
  635. - image: cimg/base:2022.06
  636. # ... steps for building/testing app ...
  637. - setup_remote_docker:
  638. version: default
  639. boolean
  640. Set this to true to enable Docker Layer Caching in the Remote Docker Environment (default: false)
  641. Version string of Docker you would like to use (default: 24.0.9). View the list of supported Docker versions here.
  642. setup_remote_docker is not compatible with the machine executor. See Docker Layer Caching in Machine Executor for information on how to enable DLC with the machine executor.
  643. The version key is not currently supported on CircleCI server. Contact your system administrator for information about the Docker version installed in your remote Docker environment. If you are on server 4.x, you can find the default AWS AMI here.
  644. Generates and stores a cache of a file or directory of files such as dependencies or source code in our object storage. Later jobs can restore this cache. Learn more on the Caching Dependencies page.
  645. Cache retention can be customized on the CircleCI web app
  646. by navigating to Plan Usage Controls.
  647. paths
  648. List of directories which should be added to the cache
  649. key
  650. Unique identifier for this cache
  651. Title of the step to be shown in the CircleCI UI (default: "Saving Cache")
  652. The cache for a specific key is immutable and cannot be changed once written.
  653. If the cache for the given key already exists it will not be modified, and job execution will proceed to the next step.
  654. When storing a new cache, the key value may contain special, templated, values for your convenience:
  655. Template Description
  656. {{ .Branch }}
  657. The VCS branch currently being built.
  658. {{ .BuildNum }}
  659. The CircleCI build number for this build.
  660. {{ .Revision }}
  661. The VCS revision currently being built.
  662. {{ .CheckoutKey }}
  663. The SSH key used to checkout the repository.
  664. {{ .Environment.variableName }}
  665. The environment variable variableName (supports any environment variable exported by CircleCI or added to a specific context--not any arbitrary environment variable).
  666. {{ checksum "filename" }}
  667. A base64 encoded SHA256 hash of the given filename’s contents. This should be a file committed in your repository and may also be referenced as a path that is absolute or relative from the current working directory. Good candidates are dependency manifests, such as package-lock.json, pom.xml or project.clj. It is important that this file does not change between restore_cache and save_cache, otherwise the cache will be saved under a cache key different than the one used at restore_cache time.
  668. {{ epoch }}
  669. The current time in seconds since the UNIX epoch.
  670. {{ arch }}
  671. The OS and CPU information. Useful when caching compiled binaries that depend on OS and CPU architecture, for example, darwin amd64 versus linux i386/32-bit.
  672. During step execution, the templates above will be replaced by runtime values and use the resultant string as the key.
  673. Template examples:
  674. myapp-{{ checksum "package-lock.json" }} - cache will be regenerated every time something is changed in package-lock.json file, different branches of this project will generate the same cache key.
  675. myapp-{{ .Branch }}-{{ checksum "package-lock.json" }} - same as the previous one, but each branch will generate separate cache
  676. myapp-{{ epoch }} - every run of a job will generate a separate cache
  677. While choosing suitable templates for your cache key, keep in mind that cache saving is not a free operation, because it will take some time to upload the cache to our storage. Best practice is to have a key that generates a new cache only if something actually changed and avoid generating a new one every time a job is run.
  678. Given the immutability of caches, it might be helpful to start all your cache keys with a version prefix v1-.... That way you will be able to regenerate all your caches just by incrementing the version in this prefix.
  679. - save_cache:
  680. key: v1-myapp-{{ arch }}-{{ checksum "project.clj" }}
  681. paths:
  682. - /home/ubuntu/.m2
  683. key: v1-{{ checksum "yarn.lock" }}
  684. - node_modules/workspace-a
  685. - node_modules/workspace-c
  686. Wildcards are not currently supported in save_cache paths. Visit the Ideas board
  687. and vote for this feature if it would be useful for you or your organization.
  688. In some instances, a workaround for this is to save a particular workspace to cache:
  689. Restores a previously saved cache based on a key. Cache needs to have been saved first for this key using the
  690. step. Learn more in the caching documentation.
  691. Single cache key to restore
  692. keys
  693. List of cache keys to lookup for a cache to restore. Only first existing key will be restored.
  694. Title of the step to be shown in the CircleCI UI (default: "Restoring Cache")
  695. (1) at least one attribute has to be present. If key and keys are both given, key will be checked first, and then keys.
  696. A key is searched against existing keys as a prefix.
  697. When there are multiple matches, the most recent match will be used, even if there is a more precise match.
  698. key: v1-myapp-cache
  699. - ~/d1
  700. key: v1-myapp-cache-new
  701. - ~/d2
  702. - run: rm -f ~/d1 ~/d2
  703. - restore_cache:
  704. In this case cache v1-myapp-cache-new will be restored because it’s the most recent match with v1-myapp-cache prefix even if the first key (v1-myapp-cache) has exact match.
  705. For more information on key formatting, see the key section of
  706. step.
  707. When CircleCI encounters a list of keys, the cache will be restored from the first one matching an existing cache. Most probably you would want to have a more specific key to be first (for example, cache for exact version of package-lock.json file) and more generic keys after (for example, any cache for this project). If no key has a cache that exists, the step will be skipped with a warning.
  708. A path is not required here because the cache will be restored to the location from which it was originally saved.
  709. keys:
  710. - v1-myapp-{{ arch }}-{{ checksum "project.clj" }}
  711. # if cache for exact version of `project.clj` is not present then load any most recent one
  712. - v1-myapp-
  713. # ... Steps building and testing your application ...
  714. # cache will be saved only once for each version of `project.clj`
  715. - /foo
  716. See
  717. for current processes. If you have parallelism > 1 in your job, see the Migrate from deploy to run guide.
  718. Step to store artifacts (for example logs, binaries, etc) to be available in the web app or through the API. See the Uploading Artifacts page for more information.
  719. Directory in the primary container to save as job artifacts
  720. destination
  721. Prefix added to the artifact paths in the artifacts API (default: the directory of the file specified in path)
  722. There can be multiple store_artifacts steps in a job. Using a unique prefix for each step prevents them from overwriting files.
  723. Artifact storage retention can be customized on the CircleCI web app
  724. name: Build the Jekyll site
  725. command: bundle exec jekyll build --source jekyll --destination jekyll/_site/docs/
  726. - store_artifacts:
  727. path: jekyll/_site/docs/
  728. destination: circleci-docs
  729. Special step used to upload and store test results for a build. Test results are visible on the CircleCI web application under each build’s Test Summary section. Storing test results is useful for timing analysis of your test suites. For more information on storing test results, see the Collecting Test Data page.
  730. It is also possible to store test results as build artifacts. For steps, refer to the
  731. step section.
  732. Path (absolute, or relative to your working_directory) to directory containing JUnit XML test metadata files, or to a single test file.
  733. Directory structure:
  734. test-results
  735. ├── jest
  736. │ └── results.xml
  737. ├── mocha
  738. └── rspec
  739. └── results.xml
  740. config.yml syntax:
  741. - store_test_results:
  742. path: test-results
  743. Special step used to persist a temporary file to be used by another job in the workflow. For more information on using workspaces, see the Using Workspaces to Share Data Between Jobs page.
  744. persist_to_workspace adopts the storage settings from the storage customization controls on the CircleCI web app. If no custom setting is provided, persist_to_workspace defaults to 15 days.
  745. Workspace storage retention can be customized on the CircleCI web app
  746. root
  747. Either an absolute path or a path relative to working_directory
  748. Glob identifying file(s), or a non-glob path to a directory to add to the shared workspace. Interpreted as relative to the workspace root. Must not be the workspace root itself.
  749. The root key is a directory on the container which is taken to be the root directory of the workspace. The path values are all relative to the root.
  750. Example for root Key
  751. For example, the following step syntax persists the specified paths from /tmp/dir into the workspace, relative to the directory /tmp/dir.
  752. - persist_to_workspace:
  753. root: /tmp/dir
  754. - foo/bar
  755. - baz
  756. After this step completes, the following directories are added to the workspace:
  757. /tmp/dir/foo/bar
  758. /tmp/dir/baz
  759. Example for paths Key
  760. root: /tmp/workspace
  761. - target/application.jar
  762. - build/*
  763. The paths list uses Glob from Go, and the pattern matches filepath.Match
  764. pattern:
  765. { term }
  766. term:
  767. '*' matches any sequence of non-Separator characters
  768. '?' matches any single non-Separator character
  769. '[' [ '^' ] { character-range }
  770. ']' character class (must be non-empty)
  771. c matches character c (c != '*', '?', '\\', '[')
  772. '\\' c matches character c
  773. character-range:
  774. c matches character c (c != '\\', '-', ']')
  775. lo '-' hi matches character c for lo <= c <= hi
  776. The Go documentation states that the pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').
  777. Everything must be relative to the work space root directory.
  778. Special step used to attach the workflow’s workspace to the current container. The full contents of the workspace are downloaded and copied into the directory the workspace is being attached at. For more information on using workspaces, see the Using workspaces page.
  779. at
  780. Directory to attach the workspace to.
  781. - attach_workspace:
  782. at: /tmp/workspace
  783. The lifetime of artifacts, workspaces, and caches can be customized on the CircleCI web app
  784. by navigating to Plan Usage Controls. Here you can control the storage retention periods for these objects. If no storage period is set, the default storage retention period of artifacts is 30 days, while the default storage retention period of workspaces and caches is 15 days.
  785. Special step that adds SSH keys from a project’s settings to a container. Also configures SSH to use these keys. For more information on SSH keys see the Create additional GitHub SSH keys page.
  786. Using server? only MD5 fingerprints are supported. In CircleCI in Project Settings SSH keys Additional SSH keys the MD5 fingerprint will be visible. SHA256 support is planned for an upcoming server release.
  787. fingerprints
  788. List of fingerprints corresponding to the keys to be added (default: all keys added)
  789. - add_ssh_keys:
  790. fingerprints:
  791. - "b7:35:a6:4e:9b:0d:6d:d4:78:1e:9a:97:2a:66:6b:be"
  792. - "SHA256:NPj4IcXxqQEKGXOghi/QbG2sohoNfvZ30JwCcdSSNM0"
  793. Even though CircleCI uses ssh-agent to sign all added SSH keys, you must use the add_ssh_keys key to actually add keys to a container.
  794. Pipeline values are available to all pipeline configurations and can be used without previous declaration. For a list of pipeline values, see the Pipeline values and parameters page.
  795. - image: cimg/node:17.2.0
  796. IMAGETAG: latest
  797. working_directory: ~/main
  798. - run: echo "This is pipeline ID << pipeline.id >>"
  799. A paid account on a Performance or Scale Plan is required to access IP ranges.
  800. Enables jobs to go through a set of well-defined IP address ranges. See IP ranges for details.
  801. circleci_ip_ranges: true # opts the job into the IP ranges feature
  802. - image: curlimages/curl
  803. - run: echo “Hello World”
  804. build-workflow:
  805. - build
  806. Used for orchestrating all jobs. Each workflow consists of the workflow name as a key and a map as a value. A name should be unique within the current config.yml. The top-level keys for the Workflows configuration are version and jobs. For more information, see the Using Workflows to Orchestrate Jobs page.
  807. The workflows version key is not required for version: 2.1 configuration
  808. The Workflows version field is used to issue warnings for deprecation or breaking changes.
  809. Y if config version is 2
  810. Should currently be 2
  811. A unique name for your workflow.
  812. Specifies which triggers will cause this workflow to be executed. Default behavior is to trigger the workflow when pushing to a branch.
  813. Array
  814. Should currently be schedule.
  815. nightly:
  816. triggers:
  817. - schedule:
  818. cron: "0 0 * * *"
  819. filters:
  820. branches:
  821. only:
  822. - main
  823. - beta
  824. - test
  825. Scheduled workflows are not available for projects integrated through the GitHub App, GitLab or Bitbucket Data Center.
  826. The scheduled workflows feature is set to be deprecated. Using scheduled pipelines rather than scheduled workflows offers several benefits. Visit the scheduled pipelines migration guide to find out how to migrate existing scheduled workflows to scheduled pipelines. If you would like to set up scheduled pipelines from scratch, visit the Scheduled pipelines page.
  827. A workflow may have a schedule indicating it runs at a certain time, for example a nightly build that runs every day at 12am UTC:
  828. The cron key is defined using POSIX crontab syntax.
  829. See the crontab man page
  830. Trigger filters can have the key branches.
  831. A map defining rules for execution on specific branches
  832. The branches key controls whether the current branch should have a schedule trigger created for it, where current branch is the branch containing the config.yml file with the trigger stanza. That is, a push on the main branch will only schedule a workflow for the main branch.
  833. Branches can have the keys only and ignore which each map to a single string naming a branch. You may also use regular expressions to match against branches by enclosing them with `/’s, or map to a list of such strings. Regular expressions must match the entire string.
  834. Any branches that match only will run the job.
  835. Any branches that match ignore will not run the job.
  836. If neither only nor ignore are specified then all branches will run the job. If both only and ignore are specified, the only is used and ignore will have no effect.
  837. commit:
  838. - deploy
  839. - /^release\/.*/
  840. - coverage
  841. only 1
  842. String, or List of Strings
  843. Either a single branch specifier, or a list of branch specifiers
  844. ignore 1
  845. 1: One of either only or ignore branch filters must be specified. If both are present, only is used.
  846. Using when or unless under workflows is supported in version: 2.1 configuration. Workflows are always run unless there is a when or unless filter that prevents the workflow from being run. If you want a workflow to run in every pipeline, do not add a when or unless filter.
  847. You may use a when clause (the inverse clause unless is also supported) under a workflow declaration with a logic statement to determine whether or not to run that workflow.
  848. The example configuration below uses a pipeline parameter, run_integration_tests to drive the integration_tests workflow.
  849. run_integration_tests:
  850. type: boolean
  851. default: false
  852. integration_tests:
  853. when: << pipeline.parameters.run_integration_tests >>
  854. - mytestjob
  855. ...
  856. This example prevents the workflow integration_tests from running unless the tests are invoked explicitly when the pipeline is triggered with the following in the POST body:
  857. {
  858. "parameters": {
  859. "run_integration_tests": true
  860. }
  861. Refer to the Workflows for more examples and conceptual information.
  862. A job can have the keys requires, name, context, type, and filters.
  863. A list of jobs to run with their dependencies
  864. A job name that exists in your config.yml.
  865. Jobs are run concurrently by default, so you must explicitly require any dependencies by their job name if you need some jobs to run sequentially.
  866. A list of jobs that must succeed for the job to start. Note: When jobs in the current workflow that are listed as dependencies are not executed (due to a filter function for example), their requirement as a dependency for other jobs will be ignored by the requires option. However, if all dependencies of a job are filtered, then that job will not be executed either.
  867. The name key can be used to invoke reusable jobs across any number of workflows. Using the name key ensures numbers are not appended to your job name (for example, sayhello-1 , sayhello-2, etc.). The name you assign to the name key needs to be unique, otherwise the numbers will still be appended to the job name.
  868. A replacement for the job name. Useful when calling a job multiple times. If you want to invoke the same job multiple times, and a job requires one of the duplicate jobs, this key is required. (2.1 only)
  869. Jobs may be configured to use global environment variables set for an organization, see the Contexts document for adding a context in the application settings.
  870. String/List
  871. The name of the context(s). The initial default name is org-global. Each context name must be unique. If using CircleCI server, only a single context per workflow is supported. Note: A maximum of 100 unique contexts across all workflows is allowed.
  872. A job may have a type of approval indicating it must be manually approved before downstream jobs may proceed. For more information see the Using workflows to orchestrate jobs page.
  873. Jobs run in the dependency order until the workflow processes a job with the type: approval key followed by a job on which it depends, for example:
  874. my-workflow:
  875. - test:
  876. requires:
  877. - hold:
  878. type: approval
  879. - deploy:
  880. - hold
  881. An approval job can have any name. In the example above the approval job is named hold. The name you choose for an approval job should not be used to define a job in the main configuration. An approval job only exists as a workflow orchestration devise.
  882. Filter job execution within a workflow based on the following:
  883. Branch
  884. Tag
  885. Expression-based condition
  886. Job filters can have the keys branches or tags.
  887. Workflows will ignore job-level branching. If you use job-level branching and later add workflows, you must remove the branching at the job level and instead declare it in the workflows section of your config.yml.
  888. A map or string to define rules for job execution. Branch and tag filters require a map. Expression-based filters require a string.
  889. The following is an example of how the CircleCI documentation project uses a regular expression to filter running a job in a workflow only on a specific branch:
  890. # ...
  891. build-deploy:
  892. - js_build
  893. - build_server_pdfs: # << the job to conditionally run based on the filter-by-branch-name.
  894. only: /server\/.*/ # the job build_server_pdfs will only run when the branch being built starts with server/
  895. You can read more about using regular expressions in your config in the Using workflows to schedule jobs page.
  896. Expression-based job filters allow you to conditionally run jobs based on the following:
  897. Pipeline values
  898. Pipeline parameters
  899. An expression-based job filter is a rule that is evaluated against pipeline values and parameters to decide whether a job should run.
  900. Using expression-based job filters is one way to optimize your pipelines to lower costs, decrease time to feedback, or run specific jobs based on the context of the source of change.
  901. deploy:
  902. - init-service
  903. - build-service-image:
  904. - dry-run-service:
  905. filters: pipeline.git.branch != "main" and pipeline.git.branch != "canary"
  906. - publish-service:
  907. - build-service-image
  908. - test-service
  909. filters: pipeline.git.branch == "main" or pipeline.git.tag starts-with "release"
  910. - deploy-service:
  911. context:
  912. - org-global
  913. - publish-service
  914. filters: pipeline.git.branch == "main" and pipeline.git.commit.subject starts-with "DEPLOY:"
  915. Examples
  916. Only run the job on the project’s main branch:
  917. filters: pipeline.git.branch == "main"
  918. Only run the job on the project’s main branch, or branches starting with integration-test:
  919. filters: pipeline.git.branch == "main" or pipeline.git.branch starts-with "integration-test"
  920. Only run the job on the main branch, and disallow use with pipelines triggered with unversioned configuration:
  921. filters: pipeline.git.branch == "main" and not (pipeline.config_source starts-with "api")
  922. Use pipeline parameters and the pipeline value pipeline.git.branch to run a job only on specific branches or when triggered via the API with a pipeline parameter set to true:
  923. run-storybook-tests:
  924. # jobs configuration ommitted for brevity
  925. - setup
  926. - storybook-tests:
  927. filters: |
  928. pipeline.parameters.run-storybook-tests
  929. or pipeline.git.branch == "dry-run-deploy"
  930. or pipeline.git.branch starts-with "deploy"
  931. You can use the API to trigger a pipeline with a pipeline parameter set to true:
  932. curl -X POST https://circleci.com/api/v2/project/circleci/<org-id>/<project-id>/pipeline/run \
  933. --header "Circle-Token: $CIRCLE_TOKEN" \
  934. --header "content-type: application/json" \
  935. --data {
  936. "definition_id": "<pipeline-definition-id>",
  937. "config": {"branch": "<your-branch-name>"},
  938. "checkout": {"branch": "<your-branch-name>"},
  939. "parameters": {"run-storybook-tests": "true"}
  940. Operators
  941. The operators you can use for expression-based job filters are described in the following table. You can also group sub-expressions with parentheses (, ). as in the examples above.
  942. Operator type Operators Description
  943. Logical
  944. and, or
  945. These are short-circuiting boolean operators.
  946. Equality
  947. ==, !=
  948. String, numeric, and boolean equality. If the operands are of different types then == will evaluate false, and != will evaluate true.
  949. starts-with
  950. String prefix equality, "hello world" starts-with "hello" evaluates as true. It is an error to use a non-string type as an operand.
  951. Numeric comparison
  952. >=, >, ⇐, <
  953. Numeric comparisons. It is an error to use a non-numeric type as an operand.
  954. Negation
  955. not
  956. Boolean negation.
  957. Note that not has very high precedence and so binds very tightly. Use sub-expressions to apply not to more complex expressions. For example, with foo being true and bar being false:
  958. not foo and bar evaluates to false
  959. not (foo and bar) evaluates to true
  960. The branches filter can have the keys only and ignore, which map to a single string naming a branch. You may also use regular expressions to match against branches by enclosing them with slashes, or map to a list of such strings. Regular expressions must match the entire string.
  961. If neither only nor ignore are specified then all branches will run the job.
  962. If both only and ignore are specified the only is considered before ignore.
  963. A map defining rules for execution on specific branches.
  964. only
  965. String, or list of strings
  966. Either a single branch specifier, or a list of branch specifiers.
  967. ignore
  968. dev_stage_pre-prod:
  969. - test_dev:
  970. filters: # using regex filters requires the entire branch to match
  971. only: # only branches matching the below regex filters will run
  972. - dev
  973. - /user-.*/
  974. - test_stage:
  975. only: stage
  976. - test_pre-prod:
  977. only: /pre-prod(?:-.+)?$/
  978. CircleCI does not run workflows for tags unless you explicitly specify tag filters. Additionally, if a job requires any other jobs (directly or indirectly), you must specify tag filters for those jobs.
  979. Tags can have the keys only and ignore. You may also use regular expressions to match against tags by enclosing them with slashes, or map to a list of such strings. Regular expressions must match the entire string. Both lightweight and annotated tags are supported.
  980. Any tags that match only will run the job.
  981. Any tags that match ignore will not run the job.
  982. If neither only nor ignore are specified then the job is skipped for all tags.
  983. A map defining rules for execution on specific tags
  984. Either a single tag specifier, or a list of tag specifiers
  985. For more information, see the Executing workflows for a git tag section of the Workflows page.
  986. untagged-build:
  987. tagged-build:
  988. - build:
  989. tags:
  990. only: /^v.*/
  991. The matrix key is supported in version: 2.1 configuration
  992. The matrix stanza allows you to run a parameterized job multiple times with different arguments. For more information see the how-to guide on Using Matrix Jobs. In order to use the matrix stanza, you must use parameterized jobs.
  993. A map of parameter names to every value the job should be called with
  994. exclude
  995. A list of argument maps that should be excluded from the matrix
  996. alias
  997. An alias for the matrix, usable from another job’s requires stanza. Defaults to the name of the job being executed
  998. The following is a basic example of using matrix jobs.
  999. workflow:
  1000. matrix:
  1001. version: ["0.1", "0.2", "0.3"]
  1002. platform: ["macos", "windows", "linux"]
  1003. This expands to 9 different build jobs, and could be equivalently written as:
  1004. name: build-macos-0.1
  1005. version: 0.1
  1006. platform: macos
  1007. name: build-macos-0.2
  1008. version: 0.2
  1009. name: build-macos-0.3
  1010. version: 0.3
  1011. name: build-windows-0.1
  1012. platform: windows
  1013. - ...
  1014. Sometimes you may wish to run a job with every combination of arguments except some value or values. You can use an exclude stanza to achieve this:
  1015. a: [1, 2, 3]
  1016. b: [4, 5, 6]
  1017. exclude:
  1018. - a: 3
  1019. b: 5
  1020. The matrix above would expand into 8 jobs: every combination of the parameters a and b, excluding {a: 3, b: 5}
  1021. To require an entire matrix (every job within the matrix), use its alias. The alias defaults to the name of the job being invoked.
  1022. version: ["0.1", "0.2"]
  1023. - another-job:
  1024. This means that another-job will require both deploy jobs in the matrix to finish before it runs.
  1025. Additionally, matrix jobs expose their parameter values via << matrix.* >> which can be used to generate more complex workflows. For example, here is a deploy matrix where each job waits for its respective build job in another matrix.
  1026. name: build-v<< matrix.version >>
  1027. name: deploy-v<< matrix.version >>
  1028. - build-v<< matrix.version >>
  1029. This workflow will expand to:
  1030. name: build-v0.1
  1031. name: build-v0.2
  1032. name: deploy-v0.1
  1033. - build-v0.1
  1034. name: deploy-v0.2
  1035. - build-v0.2
  1036. Pre-steps and post-steps are supported in version: 2.1 configuration
  1037. Every job invocation in a workflow may optionally accept two special arguments: pre-steps and post-steps.
  1038. Steps under pre-steps are executed before any of the other steps in the job. The steps under post-steps are executed after all of the other steps.
  1039. Pre and post steps allow you to execute steps in a given job without modifying the job. This is useful, for example, to run custom setup steps before job execution.
  1040. bar:
  1041. command: echo "building"
  1042. command: echo "testing"
  1043. - bar:
  1044. pre-steps: # steps to run before steps defined in the job bar
  1045. command: echo "install custom dependency"
  1046. post-steps: # steps to run after steps defined in the job bar
  1047. command: echo "upload artifact to s3"
  1048. Certain dynamic configuration features accept logic statements as arguments. Logic statements are evaluated to boolean values at configuration compilation time, that is, before the workflow is run. The group of logic statements includes:
  1049. Type Arguments true if Example
  1050. YAML literal
  1051. None
  1052. is truthy
  1053. true/42/"a string"
  1054. YAML alias
  1055. resolves to a truthy value
  1056. *my-alias
  1057. Pipeline Value
  1058. << pipeline.git.branch >>
  1059. Pipeline Parameter
  1060. << pipeline.parameters.my-parameter >>
  1061. and
  1062. N logic statements
  1063. all arguments are truthy
  1064. and: [ true, true, false ]
  1065. or
  1066. any argument is truthy
  1067. or: [ false, true, false ]
  1068. 1 logic statement
  1069. the argument is not truthy
  1070. not: true
  1071. equal
  1072. N values
  1073. all arguments evaluate to equal values
  1074. equal: [ 42, << pipeline.number >>]
  1075. matches
  1076. pattern and value
  1077. value matches the pattern
  1078. matches: { pattern: "^feature-.$", value: << pipeline.git.branch >> }+
  1079. The following logic values are considered falsy:
  1080. false
  1081. null
  1082. NaN
  1083. empty strings ("")
  1084. statements with no arguments
  1085. All other values are truthy. Also note that using logic with an empty list will cause a validation error.
  1086. Logic statements always evaluate to a boolean value at the top level, and coerce as necessary. They can be nested in an arbitrary fashion, according to their argument specifications, and to a maximum depth of 100 levels.
  1087. matches uses Java regular expressions
  1088. for its pattern. A full match pattern must be provided, prefix matching is not an option. Though, it is recommended to enclose a pattern in ^ and $ to avoid accidental partial matches.
  1089. When using logic statements at the workflow level, do not include the condition: key (the condition key is only needed for job level logic statements).
  1090. when:
  1091. or:
  1092. - equal: [ main, << pipeline.git.branch >> ]
  1093. - equal: [ staging, << pipeline.git.branch >> ]
  1094. and:
  1095. - not:
  1096. matches:
  1097. pattern: "^main$"
  1098. value: << pipeline.git.branch >>
  1099. - or:
  1100. - equal: [ canary, << pipeline.git.tag >> ]
  1101. - << pipeline.parameters.deploy-canary >>
  1102. linux-13:
  1103. - image: cimg/node:13.13
  1104. macos: &macos-executor
  1105. xcode: 14.2.0
  1106. test:
  1107. os:
  1108. type: executor
  1109. node-version:
  1110. executor: << parameters.os >>
  1111. condition:
  1112. equal: [ *macos-executor, << parameters.os >> ]
  1113. - run: echo << parameters.node-version >>
  1114. - run: echo 0
  1115. all-tests:
  1116. os: macos
  1117. node-version: "13.13.0"
  1118. Using Docker? Authenticating Docker pulls from image registries is recommended when using the Docker execution environment. Authenticated pulls allow access to private Docker images, and may also grant higher rate limits, depending on your registry provider. For further information see Using Docker authenticated pulls.
  1119. - image: ubuntu:14.04
  1120. command: [mongod, --smallfiles]
  1121. # some containers require setting environment variables
  1122. - image: rabbitmq:3.5.4
  1123. TEST_REPORTS: /tmp/test-reports
  1124. working_directory: ~/my-project
  1125. command: echo 127.0.0.1 devhost | sudo tee -a /etc/hosts
  1126. # Create Postgres users and database
  1127. # Note the YAML heredoc '|' for nicer formatting
  1128. sudo -u root createuser -h localhost --superuser ubuntu &&
  1129. sudo createdb -h localhost test_db
  1130. - v1-my-project-{{ checksum "project.clj" }}
  1131. - v1-my-project-
  1132. SSH_TARGET: "localhost"
  1133. TEST_ENV: "linux"
  1134. set -xu
  1135. mkdir -p ${TEST_REPORTS}
  1136. run-tests.sh
  1137. cp out/tests/*.xml ${TEST_REPORTS}
  1138. mkdir -p /tmp/artifacts
  1139. create_jars.sh << pipeline.number >>
  1140. cp *.jar /tmp/artifacts
  1141. key: v1-my-project-{{ checksum "project.clj" }}
  1142. - ~/.m2
  1143. # Save artifacts
  1144. path: /tmp/artifacts
  1145. destination: build
  1146. # Upload test results
  1147. path: /tmp/test-reports
  1148. deploy-stage:
  1149. working_directory: /tmp/my-project
  1150. name: Deploy if tests pass and branch is Staging
  1151. command: ansible-playbook site.yml -i staging
  1152. deploy-prod:
  1153. name: Deploy if tests pass and branch is Main
  1154. command: ansible-playbook site.yml -i production
  1155. ignore:
  1156. - develop
  1157. - /feature-.*/
  1158. - deploy-stage:
  1159. only: staging
  1160. - deploy-prod:
  1161. only: main
  1162. Suggest an edit to this page
  1163. Make a contribution
  1164. Learn how to contribute
  1165. Still need help?
  1166. Ask the CircleCI community
  1167. Join the research community
  1168. Visit our Support site
  1169. Terms of UsePrivacy PolicyCookie PolicySecurity
  1170. © 2024 Circle Internet Services, Inc., All Rights Reserved.
  1171. Configuration reference - CircleCI
  1172. 2 days ago11 min read
  1173. Introduction
  1174. Concurrency
  1175. Configuration
  1176. Contexts
  1177. Data persistence
  1178. Artifacts
  1179. Caches
  1180. Workspaces
  1181. Docker layer caching
  1182. Dynamic configuration
  1183. Execution environments
  1184. Images
  1185. Jobs
  1186. Orbs
  1187. Parallelism
  1188. Pipelines
  1189. Projects
  1190. Resource class
  1191. Steps
  1192. User roles
  1193. GitHub App, GitLab and Bitbucket Data Center users
  1194. GitHub OAuth app and Bitbucket Cloud users
  1195. Workflows
  1196. See also
  1197. This guide introduces some basic concepts to help you understand how CircleCI manages your CI/CD pipelines.
  1198. In CircleCI, concurrency refers to utilizing multiple containers to run multiple jobs at the same time. To keep the system stable for all CircleCI customers, we implement different soft concurrency limits on each of the resource classes for different executors. If you experience queueing on your jobs, you may be hitting these limits. Customers on annual plans can request an increase to those limits at no extra charge.
  1199. See the Concurrency page for more information.
  1200. CircleCI believes in configuration as code. Your entire CI/CD process is orchestrated through a single file called config.yml. The config.yml file is located in a folder called .circleci at the root of your project that defines the entire pipeline.
  1201. Example of a directory setup using CircleCI:
  1202. ├── .circleci
  1203. │ ├── config.yml
  1204. ├── README
  1205. └── all-other-project-files-and-folders
  1206. Your CircleCI configuration can be adapted to fit many different needs of your project. The following terms, sorted in order of granularity and dependence, describe the components of most common CircleCI projects:
  1207. Pipeline: Represents the entirety of your configuration.
  1208. Workflows: Responsible for orchestrating multiple jobs.
  1209. Jobs: Responsible for running a series of steps that perform commands.
  1210. Steps: Run commands (such as installing dependencies or running tests) and shell scripts to do the work required for your project.
  1211. The following illustration uses an example Java application
  1212. to show the various configuration elements:
  1213. configuration elements
  1214. CircleCI configurations use YAML. See the Introduction to YAML configurations page for basic guidance. For a full overview of what is possible in a configuration file, see the Configuration reference page.
  1215. Contexts provide a mechanism for securing and sharing environment variables across projects. The environment variables are defined as name/value pairs and are injected at runtime. After a context has been created, you can use the context key in the workflows section of a project’s .circleci/config.yml file to give any job(s) access to the environment variables associated with the context.
  1216. Contexts Overview
  1217. See the Using contexts page for more information.
  1218. Persist data to move data between jobs and speed up your build. There are three main methods for persisting data in CircleCI: artifacts, caches, and workspaces.
  1219. workflow illustration
  1220. Note the following distinctions between artifacts, caches and workspaces:
  1221. Type Lifetime Use Example
  1222. Months
  1223. Preserve long-term artifacts.
  1224. Available in the Artifacts tab of the Job page under the tmp/circle-artifacts.<hash>/container or similar directory.
  1225. Store non-vital data that may help the job run faster, for example npm or Gem packages.
  1226. The save_cache job step with a path to a list of directories to add and a key to uniquely identify the cache (for example, the branch, build number, or revision). Restore the cache with restore_cache and the appropriate key.
  1227. Duration of workflow
  1228. Attach the workspace in a downstream container with the attach_workspace: step.
  1229. The attach_workspace copies and recreates the entire workspace content when it runs.
  1230. Artifacts persist data after a workflow is completed and may be used for longer-term storage of the outputs of your build process.
  1231. build1:
  1232. - image: cimg/base:2023.03
  1233. - persist_to_workspace: # Persist the specified paths (workspace/echo-output)
  1234. # into the workspace for use in downstream job. Must be an absolute path,
  1235. # or relative path from working_directory. This is a directory on the container which is
  1236. # taken to be the root directory of the workspace.
  1237. root: workspace
  1238. # Must be relative path from root
  1239. - echo-output
  1240. build2:
  1241. image: ubuntu-2204:2024.01.2
  1242. # Must be absolute path or relative path from working_directory
  1243. build3:
  1244. - store_artifacts: # See circleci.com/docs/artifacts/ for more details.
  1245. path: /tmp/artifact-1
  1246. destination: artifact-file
  1247. - build1
  1248. - build2:
  1249. - build3:
  1250. - build2
  1251. See the Storing build artifacts page for more information.
  1252. A cache stores a file or directory of files such as dependencies or source code in object storage. To speed up the build, each job may contain special steps for caching dependencies from previous jobs.
  1253. If you need to clear your cache, refer to the Caching dependencies page for more information.
  1254. docker: # Each job requires specifying an executor
  1255. # (either docker, macos, or machine), see
  1256. # circleci.com/docs/executor-intro/ for a comparison
  1257. # and more examples.
  1258. - image: cimg/ruby:2.4-node
  1259. - image: cimg/postgres:9.4.12
  1260. - save_cache: # Caches dependencies with a cache key
  1261. # template for an environment variable,
  1262. # see circleci.com/docs/caching/
  1263. key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
  1264. - ~/circleci-demo-workflows
  1265. - restore_cache: # Restores the cached dependency.
  1266. For more information see the Caching dependencies and Caching strategies pages.
  1267. Workspaces are a workflow-aware storage mechanism. A workspace stores data unique to the job, which may be needed in downstream jobs. Each workflow has a temporary workspace associated with it. The workspace can be used to pass along unique data built during a job to other jobs in the same workflow.
  1268. See the Using workspaces page for more information.
  1269. Docker layer caching (DLC) caches the individual layers of Docker images built during your CircleCI jobs. Any unchanged layers are used on subsequent runs, rather than rebuilding the image each time.
  1270. In the .circle/config.yml snippet below, the build_elixir job builds an image using the ubuntu-2004:202104-01 Dockerfile. Adding docker_layer_caching: true below the machine executor key ensures CircleCI saves each Docker image layer as the Elixir image is built.
  1271. build_elixir:
  1272. image: ubuntu-2004:202104-01
  1273. docker_layer_caching: true
  1274. name: build Elixir image
  1275. command: docker build -t circleci/elixir:example .
  1276. - build_elixir
  1277. On subsequent commits, if the Dockerfile has not changed, DLC pulls each Docker image layer from cache during the build Elixir image step and the image builds significantly faster.
  1278. See the Docker layer caching page for more information.
  1279. Instead of manually creating your configuration for each CircleCI project, you can generate this configuration dynamically, based on specific pipeline parameters or file paths. This is especially helpful where your team is working on a monorepo (or a single repository). Dynamic configuration allows you to trigger builds from specific parts of your project, rather than rebuilding everything each time.
  1280. See the Dynamic configuration page for more information.
  1281. Each separate job defined within your configuration runs in a unique execution environment, known as executors. An executor can be a Docker container, or a virtual machine running Linux, Windows, or macOS. In some of these instances, you can set up an environment using GPU, or Arm. CircleCI also provides a machine-based and container-based self-hosted runner solution.
  1282. Illustration of a CircleCI job
  1283. An image is a packaged system that includes instructions for creating a running container or virtual machine, and you can define an image for each executor. CircleCI provides a range of images for use with the Docker executor, called convenience images (details in the images section).
  1284. build1: # job name
  1285. docker: # Specifies the primary container image,
  1286. - image: cimg/base:2022.04-20.04
  1287. - image: postgres:14.2 # Specifies the database image
  1288. # for the secondary or service container run in a common
  1289. # network where ports exposed on the primary container are
  1290. # available on localhost.
  1291. environment: # Specifies the POSTGRES_USER authentication
  1292. # environment variable, see circleci.com/docs/env-vars/
  1293. # for instructions about using environment variables.
  1294. #...
  1295. machine: # Specifies a machine image that uses
  1296. # an Ubuntu version 20.04 image with Docker 20.10.12
  1297. # and docker compose 1.29.2, follow CircleCI Discuss Announcements
  1298. # for new image releases.
  1299. image: ubuntu-2004:current
  1300. macos: # Specifies a macOS virtual machine with Xcode version 12.5.1
  1301. xcode: "12.5.1"
  1302. - build3
  1303. The primary container is defined by the first image listed in .circleci/config.yml file. This is where commands are executed. The Docker executor spins up a container with a Docker image. The machine executor spins up a complete Ubuntu virtual machine image. Further images can be added to spin up secondary/service containers.
  1304. For added security when using the Docker executor and running Docker commands, the setup_remote_docker key can be used to spin up another Docker container in which to run these commands. For more information see the Running Docker commands page.
  1305. For more information, see the Execution environments overview page.
  1306. An image is a packaged system that includes instructions for creating a running container. The primary container is defined by the first image listed in a .circleci/config.yml file. This is where commands are executed for jobs, using the Docker or machine executor.
  1307. The Docker executor spins up a container with a Docker image. CircleCI maintains convenience images for popular languages on Docker Hub.
  1308. The machine executor spins up a complete Ubuntu virtual machine image, giving you full access to OS resources and complete control over the job environment. For more information, see the Using machine page.
  1309. # an Ubuntu version 22.04 image
  1310. See the Images page for more information.
  1311. Jobs are the building blocks of your configuration. Jobs are collections of steps, which run commands/scripts as required. Each job must declare an executor that is either docker, machine, windows, or macos. For docker you must specify an image to use for the primary container. For macos you must specify an Xcode version. For windows you must use the Windows orb.
  1312. See the Jobs and steps page for more information.
  1313. Orbs are reusable snippets of code that help automate repeated processes, accelerate project setup, and help you to integrate with third-party tools.
  1314. The illustration in the Configuration section showing an example Java configuration could be simplified using orbs. The following illustration demonstrates a simplified configuration with the Maven orb. Here, the orb sets up a default executor that can execute steps with Maven and run a common job (maven/test).
  1315. Configuration using Maven orb
  1316. See Using orbs for details on how to use orbs in your configuration and an introduction to orb design. Visit the Orbs registry to search for orbs to help simplify your configuration.
  1317. The more tests your project involves, the longer it takes for them to complete on a single machine. Using test splitting and parallelism, you can spread your tests across a specified number of separate executors.
  1318. Test suites are conventionally defined at the job level in your .circleci/config.yml file. The parallelism key specifies how many independent executors will be set up to run the steps of a job. and you can use the circleci tests commands to split your test suite to run across your parallel executors.
  1319. To run a job’s steps in parallel, set the parallelism key to a value greater than 1.
  1320. - image: cimg/go:1.18.1
  1321. parallelism: 4
  1322. Executor types with parallelism
  1323. See Test splitting and parallelism page for more information.
  1324. A CircleCI pipeline is the full set of processes you run when you trigger work on your projects. Pipelines encompass your workflows, which in turn coordinate your jobs. This is all defined in your project configuration file.
  1325. Pipelines represent methods for interacting with your configuration:
  1326. Trigger a pipeline through the API with the trigger a pipeline
  1327. endpoint.
  1328. Use pipeline parameters to trigger conditional workflows.
  1329. Use version 2.1 configuration, which provides access to:
  1330. Reusable configuration elements, including executors, commands and jobs.
  1331. Packaged reusable configuration, known as orbs.
  1332. Improved configuration validation error messages.
  1333. Option to enable auto-cancel, within Advanced project settings in the web app to terminate workflows when new pipelines are triggered on non-default branches.
  1334. It is important to carefully consider the impact of enabling the auto-cancel feature, for example, if you have configured automated deployment jobs on non-default branches.
  1335. See the Pipelines overview page for more information.
  1336. For GitHub OAuth app and Bitbucket Cloud accounts, a project in CircleCI is tied to, and shares the name of the associated code repository in your VCS.
  1337. For GitHub App, GitLab SaaS and self-managed and Bitbucket Data Center users, a project in CircleCI is standalone. You name your project and then connect your code (in your GitHub, GitLab or Bitbucket Data Center repository) to that project.
  1338. Project names must meet the following requirements:
  1339. Begin with a letter
  1340. 3-40 characters long
  1341. Contain only letters, numbers, spaces, or the following characters " - _ . : ! & + [ ] " ;
  1342. A standalone project can have:
  1343. One or more configurations (pipeline definitions), including, but not limited to, a .circleci/config.yml file in the repository associated with the project.
  1344. One or more triggers (events from a source of change), including, but not limited to, a VCS. A trigger determines which configuration it should use to start a pipeline.
  1345. Select Projects in the CircleCI web app sidebar to enter the projects dashboard. On the dashboard, you can set up and follow any project you have access to. There are two options:
  1346. Set Up or Create any project that you are the owner of in your VCS.
  1347. Follow any project in your organization to gain access to its pipelines and to subscribe to email notifications for the project’s status.
  1348. Project dashboard
  1349. A resource class is a configuration option that allows you to control available compute resources (CPU and RAM) for your jobs. When you specify an execution environment for a job, a default resource class value for the environment will be set unless you define the resource class in your configuration. It is best practice to define the resource class, as opposed to relying on a default.
  1350. The example below shows how to define a resource class in the Docker execution environment.
  1351. - image: cimg/node:current
  1352. # resource class declaration
  1353. Examples for all execution environments are available on the following pages:
  1354. Using the Docker execution environment
  1355. Using the LinuxVM execution environment
  1356. Using the macOS execution environment
  1357. Using the Windows execution environment
  1358. Using the GPU execution environment
  1359. Using the Arm VM execution environment
  1360. Pricing and plans information for the various resource classes can be found on the Resource classes product page.
  1361. The resource_class key is also used to configure a self-hosted runner instance.
  1362. Steps are collections of the executable commands required to complete your job. For example, the
  1363. step (which is a built-in step available across all CircleCI projects) checks out the source code for a job over SSH. The run step allows you to run custom commands, such as executing the command make test, using a non-login shell by default. Commands can also be defined outside the job declaration, making them reusable across your configuration.
  1364. - image: cimg/base:2024.02
  1365. - checkout # Special step to checkout your source code
  1366. - run: # Run step to execute commands, see
  1367. # circleci.com/docs/configuration-reference/#run
  1368. command: make test # executable command run in
  1369. # non-login shell with /bin/bash -eo pipefail option
  1370. # by default.
  1371. CircleCI roles are set up differently depending on how you integrate your code.
  1372. To find out if you authorized through the GitHub OAuth app or the CircleCI GitHub App, see the GitHub App integration page.
  1373. Roles are set at the organization and project level and are separate to permissions and roles set in the version control system in which your code is stored. The available roles are:
  1374. Admin
  1375. Contributor
  1376. Viewer
  1377. For an overview of organization and project role permissions, see the Roles and permissions overview page.
  1378. See the Manage roles and permissions page for steps to add, remove, and change org and project level roles. You can also manages roles and permissions in groups.
  1379. CircleCI has various user roles with permissions inherited from VCS accounts.
  1380. The Organization Administrator is a permission level inherited from your VCS:
  1381. GitHub: Owner and following at least one project building on CircleCI.
  1382. Bitbucket: Admin and following at least one project building on CircleCI.
  1383. The Project Administrator is the user who adds a GitHub or Bitbucket repository to CircleCI as a Project.
  1384. A User is an individual user within an organization, inherited from your VCS.
  1385. A CircleCI user is anyone who can log in to the CircleCI platform with a username and password. Users must be added to an org in the VCS to view or follow associated CircleCI projects. Users may not view project data that is stored in environment variables.
  1386. Workflows orchestrate jobs. A workflow defines a list of jobs and their run order. It is possible to run jobs concurrently, sequentially, on a schedule, or with a manual gate using an approval job.
  1387. Workflows illustration cloud
  1388. The following configuration example shows a workflow called build_and_test in which the job build1 runs and then jobs build2 and build3 run concurrently:
  1389. name: Precompile assets
  1390. command: bundle exec rake assets:precompile
  1391. build_and_test: # name of your workflow
  1392. - build1 # wait for build1 job to complete successfully before starting
  1393. # see circleci.com/docs/workflows/ for more examples.
  1394. # run build2 and build3 concurrently to save time.
  1395. See the Using workflows page for more information.
  1396. Follow our quickstart guide to walk through setting up a working pipeline.
  1397. Concepts - CircleCI
  1398. Reusable Config Reference Guide
  1399. 1 week ago12 min read
  1400. Notes on reusable configuration
  1401. Using the parameters declaration
  1402. Parameter syntax
  1403. Parameter types
  1404. Enum
  1405. Executor
  1406. Environment variable name
  1407. Authoring reusable commands
  1408. The commands key
  1409. Invoking reusable commands
  1410. Invoking other commands in a command
  1411. Special keys
  1412. Commands usage examples
  1413. Authoring reusable executors
  1414. The executors key
  1415. Invoking reusable executors
  1416. Example of using an executor declared in config.yml with matrix jobs.
  1417. Using executors defined in an orb
  1418. Overriding keys when invoking an executor
  1419. Authoring parameterized jobs
  1420. Jobs defined in an orb
  1421. Using parameters in executors
  1422. Example build configuration using a parameterized executor
  1423. The scope of parameters
  1424. Invoking the same job multiple times
  1425. Using pre and post steps
  1426. Defining pre and post steps
  1427. Defining conditional steps
  1428. The unless step
  1429. Writing inline orbs
  1430. This guide describes how to get started with reusable commands, jobs, executors and orbs. This guide also covers the use of parameters for creating parameterized reusable elements.
  1431. Install the CircleCI CLI so that you have access to the circleci config process command (optional). This command lets you see the expanded configuration with all reusable keys processed. Follow the Using the CircleCI CLI documentation for installation instructions and tips.
  1432. CircleCI reusable configuration elements require a version: 2.1 .circleci/config.yml file.
  1433. Command, job, executor, and parameter names must start with a letter and can only contain lowercase letters (a-z), digits (0-9), underscores (_) and hyphens (-).
  1434. Parameters are declared by name under a job, command, or executor. Pipeline parameters are defined at the top level of a project configuration. See the Pipeline Values and Parameters guide for more information.
  1435. The immediate children of the parameters key are a set of keys in a map.
  1436. In the following example, a command named greeting is designed with a single parameter named to. The to parameter is used within the steps to echo Hello back to the user.
  1437. commands: # a reusable command with parameters
  1438. greeting:
  1439. default: "world"
  1440. - run: echo "Hello <<parameters.to>>"
  1441. - greeting:
  1442. to: "My-Name"
  1443. - my-job
  1444. A parameter can have the following keys as immediate children:
  1445. Key Name Description Default value
  1446. description Optional. Used to generate documentation for your orb. N/A
  1447. type Required. See Parameter Types in the section below for details. N/A
  1448. default The default value for the parameter. Required for pipeline parameters. For all other parameters, if not present, the parameter is implied to be required. N/A
  1449. This section describes the types of parameters and their usage.
  1450. The parameter types supported by orbs are:
  1451. string
  1452. integer
  1453. enum
  1454. executor
  1455. environment variable name
  1456. The parameter types supported by pipeline parameters are:
  1457. Basic string parameters are described below:
  1458. copy-markdown:
  1459. destination:
  1460. description: destination directory
  1461. default: docs
  1462. - run: cp *.md << parameters.destination >>
  1463. Strings must be enclosed in quotes if they would otherwise represent another type (such as boolean or number) or if they contain characters that have special meaning in YAML, particularly for the colon character. In all other instances, quotes are optional.
  1464. Empty strings are treated as a falsy value in evaluation of when clauses, and all other strings are treated as truthy. Using an unquoted string value that YAML interprets as a boolean will result in a type error.
  1465. Boolean parameters are useful for conditionals:
  1466. npm-install:
  1467. clean:
  1468. description: Perform a clean install
  1469. condition: << parameters.clean >>
  1470. - run: npm clean-install
  1471. not: << parameters.clean >>
  1472. - run: npm install
  1473. Boolean parameter evaluation is based on the values specified in YAML 1.1
  1474. True: y yes true on
  1475. False: n no false off
  1476. Capitalized and uppercase versions of the above values are also valid.
  1477. Boolean values may be returned as a ‘1’ for True and ‘0’ for False.
  1478. Use the parameter type integer to pass a numeric integer value.
  1479. The following example uses the integer type to populate the value of parallelism in a job:
  1480. p:
  1481. type: integer
  1482. default: 1
  1483. parallelism: << parameters.p >>
  1484. - image: cimg/base:2023.11
  1485. p: 2
  1486. The enum parameter may be a list of any values. Use the enum parameter type when you want to enforce that the value must be one from a specific set of string values.
  1487. The following example uses the enum parameter to declare the target operating system for a binary:
  1488. list-files:
  1489. default: "linux"
  1490. description: The target Operating System for the heroku binary. Must be one of "linux", "darwin", "win32".
  1491. type: enum
  1492. enum: ["linux", "darwin", "win32"]
  1493. The following enum type declaration is invalid because the default is not declared in the enum list.
  1494. default: "windows" #invalid declaration of default that does not appear in the comma-separated enum list
  1495. enum: ["darwin", "linux"]
  1496. Use an executor parameter type to allow the invoker of a job to decide what executor it will run on.
  1497. xenial:
  1498. some-value:
  1499. default: foo
  1500. SOME_VAR: << parameters.some-value >>
  1501. - image: ubuntu:xenial
  1502. bionic:
  1503. - image: ubuntu:bionic
  1504. e:
  1505. executor: << parameters.e >>
  1506. - run: some-tests
  1507. e: bionic
  1508. name: xenial
  1509. some-value: foobar
  1510. Steps are used when you have a job or command that needs to mix predefined and user-defined steps. When passed in to a command or job invocation, the steps passed as parameters are always defined as a sequence, even if only one step is provided.
  1511. run-tests:
  1512. after-deps:
  1513. description: "Steps that will be executed after dependencies are installed, but before tests are run"
  1514. type: steps
  1515. default: []
  1516. - run: make deps
  1517. - steps: << parameters.after-deps >>
  1518. The following example demonstrates that steps passed as parameters are given as the value of a steps declaration under the job’s steps.
  1519. - run-tests:
  1520. - run: echo "The dependencies are installed"
  1521. - run: echo "And now I'm going to run the tests"
  1522. The above will resolve to the following:
  1523. The environment variable name (env_var_name) parameter is a string that must match a POSIX_NAME regular expression (for example, there can be no spaces or special characters). The env_var_name parameter is a more meaningful parameter type that enables CircleCI to check that the string that has been passed can be used as an environment variable name. For more information on environment variables, see the guide to Environment Variables.
  1524. The example below shows you how to use the env_var_name parameter type for deploying to AWS S3 with a reusable build job. This example uses the AWS_ACCESS_KEY and AWS_SECRET_KEY environment variables with the access-key and secret-key parameters. If you have a deploy job that runs the s3cmd, it is possible to create a reusable command that uses the needed authentication, but deploys to a custom bucket.
  1525. Original config.yml file:
  1526. - image: ubuntu:latest
  1527. s3cmd --access_key ${FOO_BAR} \
  1528. --secret_key ${BIN_BAZ} \
  1529. ls s3://some/where
  1530. New config.yml file:
  1531. access-key:
  1532. type: env_var_name
  1533. default: AWS_ACCESS_KEY
  1534. secret-key:
  1535. default: AWS_SECRET_KEY
  1536. command:
  1537. s3cmd --access_key ${<< parameters.access-key >>} \\
  1538. --secret_key ${<< parameters.secret-key >>} \\
  1539. << parameters.command >>
  1540. access-key: FOO_BAR
  1541. secret-key: BIN_BAZ
  1542. command: ls s3://some/where
  1543. Commands are declared under the commands key of a .circleci/config.yml file. The following example defines a command called sayhello, which accepts a string parameter to:
  1544. default: "World"
  1545. - run: echo Hello << parameters.to >>
  1546. A command 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.
  1547. steps Y Sequence A sequence of steps that run inside the job that calls the command.
  1548. parameters N Map A map of parameter keys. See the Parameter Syntax section for details.
  1549. description N String A string that describes the purpose of the command. Used for generating documentation.
  1550. Reusable commands are invoked with specific parameters as steps inside a job. When using a command, the steps of that command are inserted at the location where the command is invoked. Commands may only be used as part of the sequence under steps in a job.
  1551. The following example uses the same command from the previous example – sayhello – and invokes it in the job myjob, passing it a value for the to parameter:
  1552. myjob:
  1553. - image: "cimg/base:stable"
  1554. - sayhello: # invoke command "sayhello"
  1555. to: "Lev"
  1556. Commands can use other commands in the scope of execution. For instance, if a command is declared inside an orb it can use other commands in that orb. It can also use commands defined in other orbs that you have imported (for example some-orb/some-command).
  1557. CircleCI has several special keys available to all circleci.com customers and available by default in CircleCI server installations. Examples of these keys are:
  1558. It is possible to override the special keys with a custom command.
  1559. The following is an example of part of the aws-s3 orb where a command called sync is defined:
  1560. sync:
  1561. description: Syncs directories and S3 prefixes.
  1562. arguments:
  1563. description: |
  1564. Optional additional arguments to pass to the `aws sync` command (e.g., `--acl public-read`). Note: if passing a multi-line value to this parameter, include `\` characters after each line, so the Bash shell can correctly interpret the entire command.
  1565. aws-access-key-id:
  1566. default: AWS_ACCESS_KEY_ID
  1567. description: aws access key id override
  1568. aws-region:
  1569. default: AWS_REGION
  1570. description: aws region override
  1571. aws-secret-access-key:
  1572. default: AWS_SECRET_ACCESS_KEY
  1573. description: aws secret access key override
  1574. from:
  1575. description: A local *directory* path to sync with S3
  1576. description: A URI to an S3 bucket, i.e. 's3://the-name-my-bucket'
  1577. - aws-cli/setup:
  1578. aws-access-key-id: << parameters.aws-access-key-id >>
  1579. aws-region: << parameters.aws-region >>
  1580. aws-secret-access-key: << parameters.aws-secret-access-key >>
  1581. aws s3 sync \
  1582. <<parameters.from>> <<parameters.to>> <<parameters.arguments>>
  1583. name: S3 Sync
  1584. To invoke this sync command in your 2.1 .circleci/config.yml file, see the following example:
  1585. aws-s3: circleci/aws-s3@4.1.0
  1586. deploy2s3:
  1587. - image: cimg/base:2023.06
  1588. - aws-s3/sync:
  1589. from: .
  1590. to: "s3://mybucket_uri"
  1591. - deploy2s3
  1592. Defining a build job:
  1593. aws-cli: circleci/aws-cli@5.1.1
  1594. executor: aws-cli/default
  1595. - run: mkdir bucket && echo "lorum ipsum" > bucket/build_asset.txt
  1596. from: bucket
  1597. to: "s3://my-s3-bucket-name/prefix"
  1598. - aws-s3/copy:
  1599. from: bucket/build_asset.txt
  1600. to: "s3://my-s3-bucket-name"
  1601. arguments: --dryrun
  1602. Executors define the environment in which the steps of a job will be run. When declaring a job in CircleCI configuration, you define the type of execution environment (docker, machine, macos. etc.) to run in, as well as any other parameters for that environment, including: environment variables to populate, which shell to use, what size resource_class to use, etc.
  1603. Executor declarations outside of jobs can be used by all jobs in the scope of that declaration, allowing you to reuse a single executor definition across multiple jobs.
  1604. An executor definition includes one or more of the following keys:
  1605. docker or machine or macos
  1606. In the following example my-executor is used for running the job my-job.
  1607. - image: cimg/ruby:2.5.1-browsers
  1608. - run: echo outside the executor
  1609. 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.
  1610. docker Y (1) List Options for docker executor.
  1611. resource_class N String Amount of CPU and RAM allocated to each container in a job.
  1612. machine Y (1) Map Options for machine executor.
  1613. macos Y (1) Map Options for macOS executor.
  1614. shell N String Shell to use for execution command in all steps. Can be overridden by shell in each step.
  1615. working_directory N String The directory in which to run the steps.
  1616. environment N Map A map of environment variable names and values.
  1617. The following example passes my-executor as the value of a name key under executor – this method is primarily employed when passing parameters to executor invocations:
  1618. - image: cimg/ruby:3.2.2
  1619. executor:
  1620. name: my-executor
  1621. It is also possible to allow an orb to define the executor used by all of its commands. This allows users to execute the commands of that orb in the execution environment defined by the orb’s author.
  1622. The following example declares a Docker executor with a node image, node-docker. The tag portion of the image string is parameterized with a version parameter. A version parameter is also included in the test job so that it can be passed through the job into the executor when the job is called from a workflow.
  1623. When calling the test job in the matrix-tests workflow, matrix jobs are used to run the job multiple times, concurrently, each with a different set of parameters. The Node application is tested against many versions of Node.js:
  1624. node-docker: # declares a reusable executor
  1625. version:
  1626. description: "version tag"
  1627. default: "lts"
  1628. - image: cimg/node:<<parameters.version>>
  1629. name: node-docker
  1630. version: <<parameters.version>>
  1631. - run: echo "how are ya?"
  1632. matrix-tests:
  1633. - 13.11.0
  1634. - 12.16.0
  1635. - 10.19.0
  1636. You can also refer to executors from other orbs. Users of an orb can invoke its executors. For example, foo-orb could define the bar executor:
  1637. # Yaml from foo-orb
  1638. RUN_TESTS: foobar
  1639. baz-orb could define the bar executor too:
  1640. # Yaml from baz-orb
  1641. You may use either executor from your configuration file with:
  1642. # config.yml
  1643. foo-orb: somenamespace/foo@1
  1644. baz-orb: someothernamespace/baz@3.3.1
  1645. some-job:
  1646. executor: foo-orb/bar # prefixed executor
  1647. some-other-job:
  1648. executor: baz-orb/bar # prefixed executor
  1649. Note: The foo-orb/bar and baz-orb/bar are different executors. They both have the local name bar relative to their orbs, but they are independent executors defined in different orbs.
  1650. When invoking an executor in a job, any keys in the job itself will override those of the executor invoked. For example, if your job declares a docker stanza, it will be used, in its entirety, instead of the one in your executor.
  1651. The environment variable maps are additive. If an executor has one of the same environment variables as the job, the value in the job will be used. See the Environment Variables guide for more information.
  1652. node:
  1653. - image: cimg/node:lts
  1654. ENV: ci
  1655. # The test executor below will be overwritten by the more explicit "docker" executor. Any env vars will be added.
  1656. executor: node
  1657. - run: echo "Node will not be installed."
  1658. The above config would resolve to the following:
  1659. ENV: ci # From executor.
  1660. It is possible to invoke the same job more than once in the workflows stanza of .circleci/config.yml, passing any necessary parameters as subkeys to the job. See the Parameters syntax section above for details of syntax usage.
  1661. Example of defining and invoking a parameterized job in a config.yml:
  1662. sayhello: # defines a parameterized job
  1663. description: A job that does very little other than demonstrate what a parameterized job looks like
  1664. saywhat:
  1665. description: "To whom shall we say hello?"
  1666. - run: echo "Hello << parameters.saywhat >>"
  1667. - sayhello: # invokes the parameterized job
  1668. saywhat: Everyone
  1669. When invoking the same job multiple times with parameters across any number of workflows, the build name will be changed (i.e. sayhello-1, sayhello-2, etc.). To ensure build numbers are not appended, utilize the name key. The name you assign needs to be unique, otherwise the numbers will still be appended to the job name. As an example:
  1670. - sayhello:
  1671. name: build-sayhello
  1672. name: deploy-sayhello
  1673. saywhat: All
  1674. If a job is declared inside an orb it can use commands in that orb or the global commands. It is not possible to call commands outside the scope of declaration of the job.
  1675. hello-orb
  1676. # partial yaml from hello-orb
  1677. - saywhat:
  1678. saywhat: "<< parameters.saywhat >>"
  1679. - run: echo "<< parameters.saywhat >>"
  1680. Config leveraging hello-orb
  1681. hello-orb: somenamespace/hello-orb@volatile
  1682. - hello-orb/sayhello:
  1683. To use parameters in executors, define the parameters under the given executor. When you invoke the executor, pass the keys of the parameters as a map of keys under the executor: declaration, each of which has the value of the parameter to pass in.
  1684. Parameters in executors can be of the type string, enum, or boolean. Default values can be provided with the optional default key.
  1685. python:
  1686. tag:
  1687. default: latest
  1688. myspecialvar:
  1689. - image: cimg/python:<< parameters.tag >>
  1690. MYPRECIOUS: << parameters.myspecialvar >>
  1691. name: python
  1692. tag: "2.7"
  1693. myspecialvar: "myspecialvalue"
  1694. The above would resolve to the following:
  1695. steps: []
  1696. - image: cimg/python:2.7
  1697. MYPRECIOUS: "myspecialvalue"
  1698. Parameters are in-scope only within the job or command that defined them. If you want a job or command to pass its parameters to a command it invokes, they must be passed explicitly.
  1699. - say:
  1700. # Since the command "say" doesn't define a default
  1701. # value for the "saywhat" parameter, it must be
  1702. # passed in manually
  1703. saywhat: << parameters.saywhat >>
  1704. say:
  1705. A single configuration may invoke a job multiple times. At configuration processing time during build ingestion, CircleCI will auto-generate names if none are provided or you may name the duplicate jobs explicitly with the name key.
  1706. You must explicitly name repeat jobs when a repeat job should be upstream of another job in a workflow. For example, if a job is used under the requires key of a job invocation in a workflow, you will need to explicitly name it.
  1707. - loadsay
  1708. # This doesn't need an explicit name as it has no downstream dependencies
  1709. # This needs an explicit name for saygoodbye to require it as a job dependency
  1710. name: SayHelloChad
  1711. saywhat: Chad
  1712. # Uses explicitly defined "sayhello"
  1713. - saygoodbye:
  1714. - SayHelloChad
  1715. Every job invocation may optionally accept two special arguments: pre-steps and post-steps. Steps under pre-steps are executed before any of the other steps in the job. The steps under post-steps are executed after all of the other steps.
  1716. Pre and post steps allow you to execute steps in a given job without modifying the job. This is useful, for example, in running custom setup steps before job execution.
  1717. The keys pre-steps and post-steps in jobs are available in configuration version 2.1 and later.
  1718. The following example defines pre-steps and post-steps in the bar job of the build workflow:
  1719. pre-steps:
  1720. post-steps:
  1721. Conditional steps are available in configuration version 2.1 and later.
  1722. Conditional steps run only if a condition is met at config-compile time, before a workflow runs. This means, for example, that you may not use a condition to check an environment variable, as those are not injected until your steps are running in the shell of your execution environment.
  1723. Conditional steps may be located anywhere a regular step could and may only use parameter values as inputs.
  1724. For example, an orb could define a command that runs a set of steps if invoked with myorb/foo: { dostuff: true }, but not myorb/foo: { dostuff: false }.
  1725. Furthermore, an orb author could define conditional steps in the steps key of a Job or a Command.
  1726. # Inside config.yml
  1727. preinstall-foo:
  1728. - run: echo "preinstall is << parameters.preinstall-foo >>"
  1729. condition: << parameters.preinstall-foo >>
  1730. - run: echo "preinstall"
  1731. - run: echo "don't preinstall"
  1732. - myjob:
  1733. preinstall-foo: false
  1734. preinstall-foo: true
  1735. - myjob # The empty string is falsy
  1736. Under the when key are the subkeys condition and steps. The subkey steps are run only if the condition evaluates to a truthy value.
  1737. condition Y Logic A logic statement
  1738. steps Y Sequence A list of steps to execute when the condition is truthy.
  1739. Under the unless key are the subkeys condition and steps. The subkey steps are run only if the condition evaluates to a falsy value.
  1740. steps Y Sequence A list of steps to execute when the condition is falsy.
  1741. When defining reusable configuration elements directly within your config, you can also wrap those elements within an inline orb. You may find inline orbs useful for development or for name-spacing elements that share names in a local config.
  1742. To write an inline orb, place the orb elements under that orb’s key in the orbs declaration section of the configuration. For example, if you want to import one orb to use inside another inline orb, the config could look like the example shown below, in which the inline orb my-orb imports the node orb:
  1743. my-orb:
  1744. node: circleci/node@3.0
  1745. my_command:
  1746. - run: echo "Run my tests"
  1747. my_job:
  1748. executor: node/default # Node orb executor
  1749. - my_command
  1750. main:
  1751. - my-orb/my_job
  1752. Refer to Sample Configurations for some sample configurations that you can use in your own CircleCI configuration.
  1753. Refer to Database Examples for database examples you can use in your CircleCI configuration.
  1754. Reusable Config Reference Guide - CircleCI
  1755. 3 months ago6 min read
  1756. Built-in environment variables
  1757. This page is a reference for all built-in values available for use in your CircleCI projects.
  1758. The following built-in environment variables are available for CircleCI projects. A few environment variables are available for GitHub OAuth and Bitbucket Cloud projects that have been deprecated for GitLab, GitHub App and Bitbucket Data Center support. If you must continue to use those as environment variables in your GitLab pipelines, refer to the workaround described after the list below.
  1759. Environment variables are scoped at the job level. They can be used within the context of a job but do not exist at a pipeline level, therefore they cannot be used for any logic at the pipeline or workflow level.
  1760. You cannot use a built-in environment variable to define another environment variable. Instead, you must use a run step to export the new environment variables using BASH_ENV. For more details, see Setting an Environment Variable in a Shell Command.
  1761. Variable VCS Type Value Cloud Server
  1762. CI
  1763. GitHub, Bitbucket, GitLab
  1764. true (represents whether the current environment is a CI environment)
  1765. CIRCLECI
  1766. true (represents whether the current environment is a CircleCI environment)
  1767. CIRCLE_BRANCH
  1768. The name of the Git branch currently being built.
  1769. CIRCLE_BUILD_NUM
  1770. The number of the current job. Job numbers are unique for each job.
  1771. CIRCLE_BUILD_URL
  1772. The URL for the current job on CircleCI.
  1773. CIRCLE_JOB
  1774. The name of the current job.
  1775. CIRCLE_NODE_INDEX
  1776. For jobs that run with parallelism enabled, this is the index of the current parallel run. The value ranges from 0 to (CIRCLE_NODE_TOTAL - 1)
  1777. CIRCLE_NODE_TOTAL
  1778. For jobs that run with parallelism enabled, this is the number of parallel runs. This is equivalent to the value of parallelism in your config file.
  1779. CIRCLE_OIDC_TOKEN
  1780. An OpenID Connect token signed by CircleCI which includes details about the current job.
  1781. CIRCLE_OIDC_TOKEN_V2
  1782. CIRCLE_ORGANIZATION_ID
  1783. A unique identifier for the CircleCI organization.
  1784. CIRCLE_PIPELINE_ID
  1785. A unique identifier for the current pipeline.
  1786. CIRCLE_PR_NUMBER
  1787. GitHub OAuth, Bitbucket Cloud
  1788. The number of the associated GitHub or Bitbucket pull request. Only available on forked PRs.
  1789. CIRCLE_PR_REPONAME
  1790. The name of the GitHub or Bitbucket repository where the pull request was created. Only available on forked PRs.
  1791. CIRCLE_PR_USERNAME
  1792. The GitHub or Bitbucket username of the user who created the pull request. Only available on forked PRs.
  1793. CIRCLE_PREVIOUS_BUILD_NUM
  1794. The largest job number in a given branch that is less than the current job number. Note: The variable is not always set, and is not deterministic. It is also not set on runner executors. This variable is likely to be deprecated, and CircleCI recommends users to avoid using it.
  1795. CIRCLE_PROJECT_ID
  1796. A unique identifier for the current project.
  1797. CIRCLE_PROJECT_REPONAME
  1798. GitHub, GitLab, Bitbucket
  1799. The name of the repository of the current project.
  1800. CIRCLE_PROJECT_USERNAME
  1801. The GitHub or Bitbucket username of the current project.
  1802. CIRCLE_PULL_REQUEST
  1803. The URL of the associated pull request. If there are multiple associated pull requests, one URL is randomly chosen.
  1804. CIRCLE_PULL_REQUESTS
  1805. Comma-separated list of URLs of the current build’s associated pull requests.
  1806. CIRCLE_REPOSITORY_URL
  1807. The URL of your GitHub or Bitbucket repository.
  1808. CIRCLE_SHA1
  1809. The SHA1 hash of the last commit of the current build.
  1810. CIRCLE_TAG
  1811. The name of the git tag, if the current build is tagged. For more information, see the Git tag job execution section of the Workflows page.
  1812. CIRCLE_USERNAME
  1813. The GitHub or Bitbucket username of the user who triggered the pipeline (only if the user has a CircleCI account).
  1814. CIRCLE_WORKFLOW_ID
  1815. A unique identifier for the workflow instance of the current job. This identifier is the same for every job in a given workflow instance.
  1816. CIRCLE_WORKFLOW_JOB_ID
  1817. A unique identifier for the current job.
  1818. CIRCLE_WORKFLOW_WORKSPACE_ID
  1819. An identifier for the workspace of the current job. This identifier is the same for every job in a given workflow.
  1820. CIRCLE_WORKING_DIRECTORY
  1821. The value of the working_directory key of the current job.
  1822. CIRCLE_INTERNAL_TASK_DATA
  1823. Internal. A directory where internal data related to the job is stored. We do not document the contents of this directory; the data schema is subject to change.
  1824. If you must use the environment variables that are deprecated for GitLab SaaS in your GitLab pipelines, you can recreate this functionality using pipeline values in your configuration file. The following example shows how to set an environment variable CIRCLE_PROJECT_REPONAME using the
  1825. key and populating it with the pipeline.trigger_parameters.gitlab.repo_name value:
  1826. - image: cimg/node:17.0
  1827. CIRCLE_PROJECT_REPONAME: << pipeline.trigger_parameters.gitlab.repo_name >>
  1828. - run: echo $CIRCLE_PROJECT_REPONAME
  1829. Pipeline values are available to all pipeline configurations and can be used without previous declaration. Pipeline values are scoped at the pipeline level. They are interpolated at compilation time, not workflow/job runtime.
  1830. For GitHub users, refer to the GitHub App integration or GitHub OAuth app integration guides to check which integration type applies to you.
  1831. Variable Source Type Value Cloud Server
  1832. pipeline.id
  1833. A globally unique id
  1834. representing for the pipeline.
  1835. pipeline.number
  1836. A project unique integer id for the pipeline.
  1837. pipeline.project.git_url
  1838. The URL where the current project is hosted. For example, https://github.com/circleci/circleci-docs.
  1839. pipeline.project.type
  1840. The lower-case name of the VCS provider, for example, github, bitbucket.
  1841. pipeline.git.tag
  1842. The name of the git tag that was pushed to trigger the pipeline. If the pipeline was not triggered by a tag, then this is the empty string.
  1843. pipeline.git.branch
  1844. The name of the git branch that was pushed to trigger the pipeline.
  1845. pipeline.git.branch.is_default
  1846. Whether the branch the pipeline was triggered on is the default branch.
  1847. (>= v4.7)
  1848. pipeline.git.revision
  1849. The long (40-character) git SHA that is being built.
  1850. pipeline.git.base_revision
  1851. The long (40-character) git SHA of the build prior to the one being built. Note: While in most cases pipeline.git.base_revision will be the SHA of the pipeline that ran before your currently running pipeline, there are some caveats. When the build is the first build for a branch, the variable will not be present. In addition, if the build was triggered via the API, the variable will not be present.
  1852. pipeline.trigger_source
  1853. The source that triggers the pipeline, current values are webhook, api, scheduled_pipeline.
  1854. pipeline.schedule.name
  1855. The name of the schedule if it is a scheduled pipeline. Value will be empty string if the pipeline is triggered by other sources.
  1856. pipeline.schedule.id
  1857. The unique id of the schedule if it is a scheduled pipeline. Value will be empty string if the pipeline is triggered by other sources.
  1858. pipeline.trigger_parameters.circleci.trigger_type
  1859. GitHub App, GitLab
  1860. pipeline.trigger_parameters.circleci.event_time
  1861. Timestamp CircleCI received the event
  1862. pipeline.trigger_parameters.circleci.event_type
  1863. GitLab: push, merge request
  1864. GitHub App: push
  1865. pipeline.trigger_parameters.gitlab.type
  1866. GitLab
  1867. See GitLab documentation for webhooks
  1868. and webhook events
  1869. pipeline.trigger_parameters.gitlab.ref
  1870. pipeline.trigger_parameters.github_app.ref
  1871. GitHub App
  1872. See GitHub documentation for webhook events and payloads
  1873. pipeline.trigger_parameters.gitlab.checkout_sha
  1874. pipeline.trigger_parameters.github_app.checkout_sha
  1875. pipeline.trigger_parameters.gitlab.user_id
  1876. pipeline.trigger_parameters.github_app.user_id
  1877. pipeline.trigger_parameters.gitlab.user_name
  1878. pipeline.trigger_parameters.github_app.user_name
  1879. pipeline.trigger_parameters.gitlab.user_username
  1880. pipeline.trigger_parameters.github_app.user_username
  1881. pipeline.trigger_parameters.gitlab.user_avatar
  1882. pipeline.trigger_parameters.github_app.user_avatar
  1883. pipeline.trigger_parameters.gitlab.repo_name
  1884. pipeline.trigger_parameters.github_app.repo_name
  1885. pipeline.trigger_parameters.gitlab.repo_url
  1886. pipeline.trigger_parameters.github_app.repo_url
  1887. pipeline.trigger_parameters.gitlab.web_url
  1888. pipeline.trigger_parameters.github_app.web_url
  1889. pipeline.trigger_parameters.gitlab.commit_sha
  1890. pipeline.trigger_parameters.github_app.commit_sha
  1891. pipeline.trigger_parameters.gitlab.commit_title
  1892. pipeline.trigger_parameters.github_app.commit_title
  1893. pipeline.trigger_parameters.gitlab.commit_message
  1894. pipeline.trigger_parameters.github_app.commit_message
  1895. pipeline.trigger_parameters.gitlab.commit_timestamp
  1896. pipeline.trigger_parameters.github_app.commit_timestamp
  1897. pipeline.trigger_parameters.gitlab.commit_author_name
  1898. pipeline.trigger_parameters.github_app.commit_author_name
  1899. pipeline.trigger_parameters.gitlab.commit_author_email
  1900. pipeline.trigger_parameters.gitlab.total_commits_count
  1901. pipeline.trigger_parameters.github_app.total_commits_count
  1902. pipeline.trigger_parameters.gitlab.branch
  1903. pipeline.trigger_parameters.github_app.branch
  1904. pipeline.trigger_parameters.gitlab.default_branch
  1905. pipeline.trigger_parameters.gitlab.x_gitlab_event_id
  1906. pipeline.trigger_parameters.gitlab.is_fork_merge_request
  1907. pipeline.trigger_parameters.webhook.body
  1908. Inbound webhook
  1909. The body of the payload that was sent with a custom webhook.
  1910. - image: cimg/node:20.3.0
  1911. CIRCLE_COMPARE_URL: << pipeline.project.git_url >>/compare/<< pipeline.git.base_revision >>..<<pipeline.git.revision>>
  1912. - run: echo $CIRCLE_COMPARE_URL
  1913. When using the above method to set the variables in the environment key, note that if the pipeline variable is empty it will be set to <nil>. If you need an empty string instead, set the variable in a shell command.
  1914. Project values and variables - CircleCI
  1915. Overview
  1916. Self-hosted runner overview
  1917. Self-hosted runner concepts
  1918. Container runner
  1919. Container runner installation
  1920. Container runner performance benchmarks
  1921. Container runner reference
  1922. Machine runner 3.0
  1923. Install on Linux
  1924. Install on macOS
  1925. Install on Windows
  1926. Install on Docker
  1927. Manual install on Linux and macOS
  1928. Manual install on Windows
  1929. Migrate from launch agent to machine runner 3.0 on Linux
  1930. Migrate from launch agent to machine runner 3.0 on macOS
  1931. Migrate from launch agent to machine runner 3.0 on Windows
  1932. Machine runner 3.0 configuration reference
  1933. Machine runner
  1934. Linux installation
  1935. Windows installation
  1936. macOS installation
  1937. Docker installation
  1938. Machine runner configuration reference
  1939. How-to Guides
  1940. Upgrade machine runner on server
  1941. Self-hosted runner FAQ
  1942. Troubleshoot self-hosted runner
  1943. Scaling self-hosted runner
  1944. CircleCI’s self-hosted runner overview
  1945. 4 months ago3 min read
  1946. Launch agent 1.1 deprecated
  1947. CircleCI’s self-hosted runner operation
  1948. CircleCI runner use cases
  1949. Choosing a runner execution environment
  1950. Available self-hosted runner platforms
  1951. Limitations
  1952. Use CircleCI’s self-hosted runner to run jobs on your own infrastructure. With runner, you can build and test on a wide variety of architectures, and gain additional control over the build environment.
  1953. Self-hosted runner installation options are as follows:
  1954. Install in a Kubernetes cluster, using a container runner
  1955. Install in a machine execution environment using a machine runner
  1956. The diagrams below illustrate how CircleCI’s container and machine runners extend our existing systems.
  1957. CircleCI’s container runner architecture
  1958. Figure 1. Container runner architecture
  1959. Launch agent 1.1 has been deprecated. Machine Runner 3.0 is the recommended replacement. Launch agent 1.1 will cease to be supported as of July 31, 2024.
  1960. Once a self-hosted runner is installed, the runner polls circleci.com for work, runs jobs, and returns status, logs, and artifacts to CircleCI.
  1961. CircleCI self-hosted runner is designed to meet the needs of two main use cases, as follows:
  1962. Privileged access and controls: Some customers need to be able to run jobs on-premises or on limited-access infrastructure due to strict isolation requirements. Self-hosted runner enables the following:
  1963. IP restrictions. Self-hosted runners can have static IP addresses that you can control.
  1964. Identity Access Management (IAM) permissions. If you set up self-hosted runners in AWS, they can be assigned IAM permissions.
  1965. Ability to monitor the operating system.
  1966. Ability to connect to private networks.
  1967. Unique compute requirements: Use self-hosted runners to run your jobs in an environment or architecture that CircleCI does not offer as a resource class.
  1968. CircleCI offers two types of self-hosted runners: container and machine.
  1969. Container runner is installed in a Kubernetes cluster. Using Kubernetes enables you to run containerized jobs on self-hosted compute, similar to how jobs use the native Docker executor to run on CircleCI’s cloud platform. Container runner allows you to run hundreds of jobs at once, scaling pods effectively to meet compute demands. Container runner is a complement to the machine runner, not a replacement.
  1970. CircleCI’s self-hosted runner has historically executed each job using a one-to-one mapping between the CI job and a machine environment (virtual or physical). Each machine runner would have the self-hosted runner binary installed on it. Running jobs in this manner sacrifices several benefits of a container-based solution that are afforded on CircleCI’s cloud platform when using the Docker executor:
  1971. The ability to seamlessly use custom Docker images during job execution.
  1972. Access to a consistent, clean, containerized build environment with every job.
  1973. After installation of the container-agent, the container runner will claim your containerized jobs, schedule them within an ephemeral pod, and execute the work within a container-based execution environment.
  1974. Container runner allows you to use CircleCI’s convenience images as well as custom Docker images.
  1975. Refer to the Container runner performance benchmarks page for a look at container runner performance.
  1976. Machine runner is installed either in a virtual machine, or natively, on a physical machine. Each machine runner job executes in the same environment (virtual or physical) where the self-hosted runner binary is installed. CircleCI’s machine runner can be installed on Linux, Windows, or macOS. Machine runner should be used if you are not running containerized CI jobs. Visit the Docker to machine page for more examples on when to use a machine execution environment.
  1977. If you do not use Kubernetes but still want to run your CI job in a container on a self-hosted runner, you can install the machine runner in Docker.
  1978. Machine runner is not compatible with CircleCI’s convenience images or custom Docker images.
  1979. To get started with CircleCI’s self-hosted runners:
  1980. Provide your own platform for your self-hosted runners (see the following Available self-hosted runner platforms section for supported platforms).
  1981. You will need at least one credit on your account to use runners. Runner execution itself does not require credits but one credit is required in case your jobs use storage or networking. For more information, see the Persisting data overview.
  1982. For container runner installation, visit the Container runner installation page.
  1983. For machine runner, visit the installation guide for your desired platform:
  1984. Linux
  1985. macOS
  1986. Windows
  1987. Docker
  1988. Supported level platforms ensure that CircleCI’s self-hosted runners are both built and tested on their respective systems.
  1989. Using a supported platform, you get the following:
  1990. Documentation and best practices.
  1991. Support. CircleCI customer engineers will assist you to resolve issues within the usual Advanced Service Level Agreements (SLAs)
  1992. Supported self-hosted runners are available on the following platforms:
  1993. Container and machine self-hosted runners:
  1994. Ubuntu 18.04 or later (x86_64, ARM64)
  1995. Container runners:
  1996. Kubernetes (x86_64, ARM64)
  1997. Machine runners:
  1998. macOS X 11.2+ (Intel, Apple M1)
  1999. Windows Server 2019, 2016 (x86_64)
  2000. Linux distributions - RHEL8, SUSE, Debian, etc (x86_64, ARM64, s390x, ppc64le)
  2001. CircleCI sometimes offers a preview level platform when a new platform for self-hosted runner is in active development. If there is a platform in a preview level, this section will be updated with information and limitations for that platform.
  2002. Almost all standard CircleCI features are available for use with self-hosted runner jobs, however, a few features are not yet supported.
  2003. The following built-in environment variables are not populated within runner executors:
  2004. All deprecated cloud environment variables
  2005. For limitations relating to container runner, visit the Container runner page.
  2006. Runner Concepts
  2007. Container runner reference guide
  2008. Machine runner reference guide
  2009. Self-hosted runner change log
  2010. CircleCI’s self-hosted runner overview - CircleCI
  2011. Self-hosted runner Concepts
  2012. 10 months ago2 min read
  2013. Namespaces and resource classes
  2014. Task-agent
  2015. Container-agent
  2016. Machine runner 3
  2017. Launch-agent
  2018. Self-hosted runner concurrency
  2019. Public repositories
  2020. Self-hosted runners require both a namespace and a resource class.
  2021. A namespace is a unique identifier claimed by a CircleCI organization. Each CircleCI organization can claim one unique and immutable namespace. Typically, the namespace chosen is the lowercase representation of your organization’s name on your VCS (this is suggested).
  2022. A resource class is a label to match your CircleCI job with a type of runner that is identified to process that job. The first part of the resource class is your organization’s namespace. For example, a CircleCI resource class could be circleci/documentation. Resources classes are created when you go through the process of installing self-hosted runners.
  2023. Resource classes help you identify a pool of self-hosted runners, which allow you to set up your configuration to send jobs to specific places. For example, if you have multiple machines running macOS, and multiple machines running Linux, you could create resource classes for each of these, orgname/macOS and orgname/linux, respectively. At the job level in your .circleci/config.yml, you can associate which self-hosted runner resources to send a job to based on the resource class.
  2024. Optionally, you can give your resource class a description.
  2025. Please note, if you are already using orbs, you have an existing namespace. Your self-hosted runner namespace will be the same one you are using for orbs. If you need to change your namespace, please contact support
  2026. The task-agent handles running a task retrieved and configured by the container runner or machine runner. Task-agents run with the same privileges as circleci.
  2027. The container-agent gets installed with container runner. Container-agent polls CircleCI for jobs, spins up ephemeral pods with an injected task-agent, and executes each job within each pod. The pods are torn down after the jobs have completed.
  2028. The machine runner 3.0 replaces launch-agent on cloud and server v4.4+, bringing improvements to network resiliency, installation, and the upgrade process. As with launch-agent, any user who is able to execute a job will be able to gain the same privileges as the task-agent, which when installed using the provided packages runs as the circleci user.
  2029. The launch-agent manages gathering the information required to run a task with machine runner (defined as a parallel run of a job) while also downloading and launching the task-agent process.
  2030. The system has been designed to allow admins to configure the task-agent to run with a lower level of privileges than the launch-agent. Any user who is able to execute a job will be able to gain the same privileges as the task-agent. The launch-agent will run as root, but the task-agent will run as circleci.
  2031. Launch-agent is currently supported on Server v4.x and v3.x. Cloud users and server v4.4+ users should instead refer to Machine Runner 3.
  2032. Rather than limit the total number of registered self-hosted runners, CircleCI’s self-hosted runners are limited by the total number of self-hosted runner jobs (tasks) across your organization.
  2033. CircleCI’s self-hosted runners are not available for use with public projects that have the Build forked pull requests setting enabled. This feature is not availalbe for security reasons. A malicious actor may alter your machine or execute code on it by forking your repository, committing code, and opening a pull request. Untrusted jobs running on your CircleCI’s self-hosted runner pose significant security risks for your machine and network environment, especially if your machine persists its environment between jobs. Some of the risks include:
  2034. Malicious programs running on the machine
  2035. Escaping the machine’s self-hosted runner sandbox
  2036. Exposing access to the machine’s network environment
  2037. Persisting unwanted or dangerous data on the machine
  2038. Organizations are, by default, limited to claiming only one namespace. This policy is designed to limit name-squatting and namespace noise. If you need to change your namespace, please contact support
  2039. Self-hosted runner Concepts - CircleCI
  2040. CircleCI’s self-hosted runner API
  2041. 3 weeks ago2 min read
  2042. Authentication methods
  2043. Circle-Token (personal authentication)
  2044. Browser session authentication
  2045. Resource class token authentication
  2046. Supported methods
  2047. Endpoints
  2048. GET /api/v3/runner
  2049. Request
  2050. Response
  2051. Response schema
  2052. GET /api/v3/runner/tasks
  2053. GET /api/v3/runner/tasks/running
  2054. This document contains all the external facing endpoints for the CircleCI’s self-hosted runner API. This API is separate from the main CircleCI v2 API and is used for the management and execution of self-hosted runner jobs. It is hosted at runner.circleci.com
  2055. The CircleCI’s self-hosted runner API contains different authentication methods. Each authentication method may be used in different endpoints for different purposes. Also, one endpoint may accept multiple authentication methods.
  2056. This authentication method is based on personal tokens and follows the same rules for CircleCI v2 API.
  2057. Name Description
  2058. Circle-Token header
  2059. Header that contains the <circle-token> used to authenticate the user.
  2060. HTTP Basic auth username
  2061. The token can be provided using the Basic scheme, where username should be set as the <circle-token> and the password should be left blank.
  2062. Ring-session sent through a cookie on the request. This authentication allows users that are already logged into CircleCI.com to access certain endpoints seamlessly.
  2063. This token is generated when creating a new resource class. This token is only displayed once when creating a resource class, and cannot be retrieved again. This token is used exclusively by the self-hosted runner agents for claiming tasks.
  2064. HTTP Bearer auth
  2065. The token that should be provided using the Bearer scheme.
  2066. Lists the available self-hosted runners based on the specified parameters. It is mandatory to use one parameter to filter results.
  2067. This allows the endpoint to be accessible on circleci.com/api/v3/runner for users that have already logged into circleci.com
  2068. Name Type Input Required Description
  2069. resource-class
  2070. query
  2071. filters the list of self-hosted runners by specific resource class.
  2072. namespace
  2073. filters the list of self-hosted runners by namespace.
  2074. curl -X GET https://runner.circleci.com/api/v3/runner?resource-class=test-namespace/test-resource \
  2075. -H "Circle-Token: secret-token"
  2076. curl -X GET https://runner.circleci.com/api/v3/runner?namespace=test-namespace \
  2077. Status Description Format
  2078. List of agents
  2079. JSON
  2080. Name Type Required Description
  2081. items
  2082. [object]
  2083. true
  2084. array containing the self-hosted runners
  2085. self-hosted runner resource class
  2086. hostname
  2087. self-hosted runner hostname
  2088. self-hosted runner name
  2089. first_connected
  2090. string (date-time)
  2091. first time the self-hosted runner was connected
  2092. last_connected
  2093. last time the self-hosted runner was connected
  2094. last_used
  2095. last time the self-hosted runner was used to run a job
  2096. version of the machine runner launch-agent running
  2097. "items": [
  2098. "resource_class": "test-namespace/test-resource",
  2099. "hostname": "bobby",
  2100. "name": "bobby-sue",
  2101. "first_connected": "2020-05-15T00:00:00Z",
  2102. "last_connected": "2020-05-16T00:00:00Z",
  2103. "last_used": "2020-05-17T00:00:00Z",
  2104. "version": "5.4.3.2.1"
  2105. ]
  2106. Get the number of unclaimed tasks for a given resource class.
  2107. filters tasks by specific resource class.
  2108. curl -X GET https://runner.circleci.com/api/v3/runner/tasks?resource-class=test-namespace/test-resource \
  2109. Number of unclaimed tasks
  2110. unclaimed_task_count
  2111. int
  2112. number of unclaimed tasks
  2113. "unclaimed_task_count": 42
  2114. Get the number of running tasks for a given resource class.
  2115. Browser Session Authentication
  2116. This allows the endpoint to be accessible on circleci.com/api/v3/runner for users that have already logged into circleci.com.
  2117. curl -X GET https://runner.circleci.com/api/v3/runner/tasks/running?resource-class=test-namespace/test-resource \
  2118. Number of running tasks
  2119. running_runner_tasks
  2120. number of running tasks
  2121. "running_runner_tasks": 42
  2122. CircleCI’s self-hosted runner API - CircleCI
  2123. CircleCI’s self-hosted runner FAQs
  2124. 8 months ago8 min read
  2125. FAQs
  2126. What is a CircleCI task vs. a job?
  2127. What is a runner resource class? What is a resource class token?
  2128. What is the security model for CircleCI’s self-hosted runners?
  2129. How do I install dependencies needed for my jobs that use machine runners?
  2130. What connectivity is required?
  2131. How do caching, workspaces, and artifacts work with CircleCI’s self-hosted runners?
  2132. What are the best practices for managing state between jobs?
  2133. How long do inactive self-hosted runners persist in the self-hosted runner inventory page?
  2134. Can I delete self-hosted runner resource classes?
  2135. Who can create, delete, and view self-hosted runner resource classes?
  2136. Can I delete runner resource class tokens?
  2137. Can I create additional runner resource class tokens?
  2138. Can jobs on forks of my OSS project use my organization’s self-hosted runners if the fork is not a part of my organization?
  2139. Why did my test splitting job step error with circleci: command not found?
  2140. Container runner specific FAQs
  2141. Is there only one resource class allowed per container runner deployment?
  2142. Does container runner use a pull or push based model?
  2143. Does container runner scale my Kubernetes cluster for me?
  2144. Is there a limit for the number of concurrent tasks that container runner can handle?
  2145. Can I build Docker images with container runner either via Remote Docker or Docker in Docker (DIND)?
  2146. Can I use something other than Kubernetes with container runner?
  2147. Does container runner require specific Kubernetes providers?
  2148. Does container runner need to sit within the cluster that it deploys pods to?
  2149. What platforms can you install container runner on?
  2150. Does container runner support arm64 Docker images?
  2151. How do I uninstall container runner?
  2152. Does container runner replace the existing self-hosted runner from CircleCI?
  2153. If there are two container runners deployed to a single Kubernetes cluster, how does the agent.maxConcurrentTasks parameter work?
  2154. How do I upgrade to the latest Helm chart?
  2155. How is container runner versioned?
  2156. How is a version of container runner supported?
  2157. What are the security considerations for container runner?
  2158. How can an IAM role be used to authorize pulling images from ECR?
  2159. What if I want to run my CI job within a container, but do not want to use Kubernetes?
  2160. Machine runner specific FAQs
  2161. How can I tell whether a host with a self-hosted runner installed is executing a job?
  2162. This page answers frequently asked questions for CircleCI’s self-hosted container and machine runners.
  2163. A task is the smallest unit of work on CircleCI. If a job has parallelism of one, it is one task. If a job has parallelism = n and n > 1, then the job creates n tasks to execute.
  2164. A resource class is a label to match your CircleCI job with a type of runner (or container runner) that is identified to process that job. The first part of the resource class is your organization’s namespace. For example, a CircleCI resource class could be circleci/documentation.
  2165. Resource classes help you identify a pool of self-hosted runners, which allow you to set up your configuration to send jobs to specific resources. For example, if you have multiple machines running macOS, and multiple machines running Linux, you could create resource classes for each of these, orgname/macOS and orgname/linux, respectively. At the job level in your .circleci/config.yml, you can associate which self-hosted runner resources to send a job to based on the resource class.
  2166. Every time you create a resource class, a resource class token is generated that is associated with the given resource class. This token is the method by which CircleCI authenticates that the resource class is valid. The resource class token only has access to claim tasks.
  2167. Machine runners let you choose the user that executes jobs when the self-hosted runner is installed. It is up to you to ensure this user only has permissions you are comfortable letting jobs use. The container runner installation page describes the security model for container runners.
  2168. Allowing jobs to access a Docker daemon is equivalent to providing root access to the machine.
  2169. Install dependencies in one of two ways:
  2170. Allow the jobs to install their own dependencies
  2171. This approach is the most flexible, but will require providing the jobs sufficient privileges to install tools or install the tools in a non-overlapping manner. For example into the working directory.
  2172. Pre-install dependencies on the machine where the machine runner is installed
  2173. This approach is the most secure; however, this means that if the job’s dependencies change, the self-hosted runner machine must be reconfigured.
  2174. In order to connect back to CircleCI to receive and execute jobs, outbound HTTPS connections to runner.circleci.com, circleci-binary-releases.s3.amazonaws.com are required.
  2175. No inbound connectivity is required by a self-hosted runner. Any other required connectivity is dependent on the content of the jobs themselves.
  2176. Using the checkout step will require access to your VCS provider. Using the cache, workspace or artifact features will require outbound HTTPS connections to circleci-tasks-prod.s3.us-east-1.amazonaws.com.
  2177. Caches, workspaces, and artifacts are methods you can implement to help persist data between jobs, and speed up builds. All three features are compatible with self-hosted runners.
  2178. Find out more about these concepts below:
  2179. Caching
  2180. You can also find out more on the Persisting data page.
  2181. If you would prefer to take complete control of artifact storage, CircleCI recommends you avoid the built-in steps and upload the artifacts directly to your chosen storage backend.
  2182. Machine runners are not opinionated about state between jobs. Machine runners can be configured to give each job a unique working directory and clean it up afterwards - but this is optional. And by default, nothing restricts the job from placing files outside of its working directory.
  2183. In general CircleCI recommends jobs rely on as little state as possible to improve their reproducibility. An effective way to accomplish this is to put cleanup steps at the start of a job so they are guaranteed to run regardless of what happened to a previous job.
  2184. It may be possible to reduce build times by making use of caches that persist on the host between jobs, however this is a trade-off against reproducibility - and may also lead to disks filling up over time. As a result, this trade-off could lead to higher billable usage.
  2185. If a self-hosted runner has not contacted CircleCI in 12 hours, it will not show up in the inventory page on the CircleCI web app
  2186. Yes, self-hosted runner resource classes can be deleted through the CLI. Be sure you want to permanently delete the resource class and its associated tokens, as this action cannot be undone.
  2187. circleci runner resource-class delete <resource-class> --force
  2188. Organization admins in your VCS provider can create and delete self-hosted runner resource classes. Any organization user in your VCS provider that the resource class is associated with can view the resource class list through the CLI.
  2189. Yes, runner resource class tokens can be deleted through the CLI. Be sure you want to permanently delete the token as this action cannot be undone. Note this will not delete the resource class itself, only the token.
  2190. To get the list of tokens and their identifiers:
  2191. circleci runner token list <resource-class name>
  2192. To delete the token itself:
  2193. circleci runner token delete <token identifier>
  2194. Yes, additional runner resource class tokens for a specific runner resource class can be created through the CLI.
  2195. To create the token:
  2196. circleci runner token create <resource-class-name> <nickname>
  2197. No, runner resource classes cannot be used by jobs that are not associated with the organization that owns the runner resource classes. Only forks of your OSS project that are a part of your organization may use the organization’s self-hosted runners.
  2198. On self-hosted runners, circleci-agent is used for all commands in which you may use either circleci-agent or circleci on CircleCI cloud (such as test splitting and step halt commands). Note, circleci is not to be confused with the local CircleCI CLI, and is simply an alias of circleci-agent.
  2199. If you would like to use the local CircleCI CLI in your self-hosted runner jobs, which can proxy test commands to circleci-agent, you can install the CLI via a job step. Install the CLI as a dependency on your machine for machine runner, or include it in a Docker image for container runner.
  2200. This section answers frequently asked questions for CircleCI’s container runner.
  2201. No, you can use as many resource classes as you desire with your container runner deployment. At least one resource class is required in order to run a job successfully with container runner.
  2202. Container runner uses a pull-based model.
  2203. Container runner itself is its own deployment of a single replica set that does not currently require scaling. Container runner will not scale the Kubernetes cluster itself. It schedules work if there are available resources in the cluster.
  2204. You can use the queue depth API as a signal for cluster scaling.
  2205. Container runner will claim and schedule work up to your runner concurrency limit. Additionally, by default, container runner is configured with a limit of 20 tasks it will allow to be concurrently scheduled and running. This can be configured via Helm to be a different value if your runner concurrency allows for a value greater than 20. See the agent.maxConcurrentTasks parameter on the Container runner page.
  2206. An organization’s runner concurrency limit is shared with any existing machine self-hosted runners. If you do not know what your organization’s runner concurrency limit is, ask your point of contact at CircleCI, or submit a support ticket
  2207. See building container images for details.
  2208. At this time, no. Kubernetes and Helm are required.
  2209. No, any Kubernetes provider can be used.
  2210. At this time, yes.
  2211. amd64 and arm64 Linux for both container runner, and the pods that execute tasks.
  2212. Yes, container runner supports jobs that use either amd64 or arm64 Docker images, as well as Kubernetes clusters that use a mixture of amd64 and arm64 nodes. When using images built for a specific architecture, resource classes will need to be configured to target a node with that CPU architecture. Kubernetes provides several node labels automatically that are helpful in configuring the resource class pod specifications for a job to be deployed on the correct node. An example resource class configuration is shown in the example below. More information about these labels can be found in the Kubernetes documentation
  2213. agent:
  2214. resourceClasses:
  2215. <amd64 image resource class>:
  2216. token: <amd64 resource class token>
  2217. spec:
  2218. nodeSelector: # nodeSelector will cause this resource class to only create pods on nodes with the specified labels and values
  2219. kubernetes.io/arch=amd64
  2220. <arm64 image resource class>:
  2221. token: <arm64 resource class token>
  2222. nodeSelector:
  2223. kubernetes.io/arch=arm64
  2224. <multiarchitecture image resource class>: # note no nodeSelector is defined for the multiarchitecture image resource class
  2225. token: <multiarchitecture resource class token>
  2226. To uninstall the container-agent deployment, run:
  2227. $ helm uninstall container-agent
  2228. The command removes all the Kubernetes objects associated with the chart and deletes the release.
  2229. No, container runner is meant to complement machine runners. With container runner and machine runners, CircleCI users have the flexibility to choose the execution environment they desire (Container vs. Machine) just like they are afforded on CircleCI’s cloud platform.
  2230. The agent.maxConcurrentTasks parameter applies to each agent individually. However, multiple container runner deployments per Kubernetes cluster is not recommended at this time.
  2231. Updates to the Helm chart can be applied
  2232. via:
  2233. $ helm repo update
  2234. $ helm upgrade container-agent
  2235. Container runner uses semantic versioning
  2236. for both the container runner application as well as the Helm chart used for installation. The container runner image
  2237. provides a floating tag for each major and minor version, that points to the most recent release of each, as well as a fully qualified tag that points to a specific patch release for a minor version.
  2238. The container runner application promises backwards compatibility for releases within the same major version, as well as vulnerability and bug support for the most recent minor version. The Helm chart for container runner promises backwards compatibility with the values file within the same major version.
  2239. Just like a machine runner, a container runner allows users to run arbitrary code in the infrastructure where container runner is hosted, meaning a bad actor could potentially use it as a method to gain knowledge of internal systems. Ensure you are following all best practices for security to mitigate this risk.
  2240. An IAM role can be associated with the service account used for the container runner by following the AWS documentation
  2241. . If an image in a job configuration specifies AWS credentials, those credentials will be used instead of the IAM role attached to the container runner service account. See the Container runner documentation for more details about the container runner service account.
  2242. If you would like to run your CI job within a container, but do not want to use Kubernetes, you can use a machine runner with Docker installed.
  2243. This section answers frequently asked questions for CircleCI’s machine runner.
  2244. The recommended approach at this time is to query the host with the following command:
  2245. ps aux | pgrep -f circleci-launch-agent
  2246. If the result of the command above returns greater than two processes, you can assume that the machine runner is executing a task.
  2247. Note that you must check to see if there are greater than two processes because the grep process itself will count as one process and the launch-agent process will count as a separate process.
  2248. CircleCI’s self-hosted runner FAQs - CircleCI