---
title: "Tech Tip #76: Tear down CI environments after use"
description: "Your preview environments are still running from last month."
url: https://greencode.ai/tech-tips/76-tear-down-ci-environments/
---

# Tech Tip #76: Tear down CI environments after use

**Your preview environments are still running from last month.**

### The problem

Per-branch previews, staging copies and CI runners stay up long after the work is merged. Multiple near-identical environments run in parallel for convenience.

### The fix you can use today

- Create environments on demand and destroy them automatically when a branch closes.
- Consolidate dev, staging and QA where isolation allows.
- Cache build dependencies instead of rebuilding from scratch every run.

### Tools that help

- [GreenCode Constitution skill](https://greencode-constitution.org/?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode) (GreenCode researchers): open-source energy principles and a catalogue of 37 energy anti-patterns that an AI coding agent can follow to find and fix waste like this
- [Eco CI](https://github.com/green-coding-solutions/eco-ci-energy-estimation?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode): estimates the energy of CI pipeline runs on GitHub Actions and GitLab, per step

### How GreenCode helps

GreenCode helps tackle this by mapping a running estate, rebuilding it as infrastructure as code and showing which services use the energy, including services barely running at all. [More on this](https://greencode.ai/feature/infrastructure-carbon-footprint-assessment/).

### Tags

#ci-cd#cloud#idle

### Sources

- [GreenCode Constitution skill, energy anti-patterns: N2 redundant deployment environments and N3 persistent CI/CD environments (Tier 4)](https://greencode-constitution.org/skill.md?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode)
- [Green Software Foundation, Green Software Patterns: Minimize the total number of deployed environments](https://github.com/Green-Software-Foundation/patterns/blob/main/docs/development/minimizing-deployed-environments.md?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode)
- [HashiCorp, HCP Terraform: auto-destroy workspaces on a schedule or after inactivity](https://developer.hashicorp.com/terraform/cloud-docs/workspaces/settings/deletion?utm_source=greencode.ai&utm_medium=referral&utm_campaign=greencode)
- [W3C, Web Sustainability Guidelines: remove unused virtual and physical environments](https://www.w3.org/TR/web-sustainability-guidelines/#unused-environments)

[All GreenCode Tech Tips](https://greencode.ai/tech-tips/)

#### Key Facts

- Tip **#76**
- For **Ops and infrastructure**
- Category **Testing, CI and code quality**
- Format **short video**
![GreenCode](https://greencode.ai/wp-content/uploads/2024/12/greencode-logo-website-small-colours-2.webp)

Want this checked on your own system? Talk to the GreenCode team.

[Get in touch](https://greencode.ai/contact/)
