> ## Documentation Index
> Fetch the complete documentation index at: https://docs.macstadium.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use a fresh VM for each CI job

> Deploy a new Orka VM for every CI job and delete it when the job ends, so builds start clean, node capacity frees up, and leftover VMs don't pile up.

Run each CI job on a VM deployed for that job, and delete the VM when the job ends. Every build then starts from the same image, nothing one job leaves behind affects the next, and the node's CPU and memory go back to the pool as soon as the job is done.

## Deploy at the start, delete at the end

Orka's CI integrations deploy and delete VMs for you. The [GitHub Actions runner](https://docs.macstadium.com/orka/orka-devops-integrations/github-actions.md) tears down each runner VM after its job. The [Jenkins plugin](https://docs.macstadium.com/orka/orka-devops-integrations/jenkins.md)'s ephemeral agent pool deletes a VM after an idle period, so one VM can run more than one build before it's deleted.

If you script it yourself, delete the VM even when the job fails or is canceled:

```bash theme={null}
VM_NAME="ci-<JOB_ID>"
trap 'orka vm delete "$VM_NAME"' EXIT
orka vm deploy "$VM_NAME" --config <VM_CONFIGURATION_NAME>

# Run the build on the VM
```

If your CI tool runs cleanup separately from the job's script, put the delete there instead, for example a step with `if: always()` in GitHub Actions, `after_script` in GitLab CI, or a `pre-exit` hook in Buildkite.

Name each VM after its job, such as `ci-<JOB_ID>`, so a VM that outlives its job can be traced back to it.

## Don't keep VMs between jobs

It can be tempting to keep a warm VM around and reuse it. Avoid it:

* **Its disk is temporary.** If a node goes down for more than a few minutes, Orka deploys the VM again from its original image, and anything you changed inside it is gone. See [What happens if a node goes down?](https://docs.macstadium.com/orka/orka-overview/how-orka-manages-vms.md#what-happens-if-a-node-goes-down).
* **It holds capacity.** A running VM keeps its CPU and memory on the node while it waits for work, and each node runs at most two macOS VMs.
* **It drifts.** Each job leaves files, caches, and processes behind, so later jobs don't run on the image you tested.

If jobs need something that's slow to set up, such as Xcode, toolchains, or dependencies, put it in the image you deploy from, and push a new version of the image when it changes. See [How do you keep changes you make inside a VM?](https://docs.macstadium.com/orka/orka-overview/how-orka-manages-vms.md#how-do-you-keep-changes-you-make-inside-a-vm).

## Clean up leftover VMs

A job that's killed outright, for example when its CI agent crashes, can skip its cleanup. Check now and then for CI VMs whose jobs have finished, and delete them:

```bash theme={null}
orka vm list
orka vm delete <VM_NAME>
```

A consistent name prefix like `ci-` makes them easy to spot.

## Related pages

* [How Orka manages VMs](https://docs.macstadium.com/orka/orka-overview/how-orka-manages-vms.md)
* [Orka CLI VM config templates and deployment](https://docs.macstadium.com/orka/orka-cli-reference/vm-deployment-and-configuration.md)
* [Orka CI/CD integrations quick start guide](https://docs.macstadium.com/orka/quick-start-guides/cicd-integrations-quick-start.md)


## Related topics

- [Run the Orka CLI from parallel CI jobs](https://docs.macstadium.com/orka/orka-best-practices/parallel-orka-cli-jobs.md)
- [Start from a larger base image instead of resizing](https://docs.macstadium.com/orka/orka-best-practices/start-with-a-larger-disk.md)
- [How access works in Orka](https://docs.macstadium.com/orka/orka-cluster-access/how-access-works.md)
- [Harness CI on Orka: Orka-side setup](https://docs.macstadium.com/orka/orka-devops-integrations/harness.md)
- [Azure DevOps agents on Orka](https://docs.macstadium.com/orka/orka-devops-integrations/azure-devops.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.