Course contentsShow
← Cloud and Infrastructure
Lesson 1780 of 2,98937. JenkinsFree lesson

Workspace Management and Build Artifacts

Understand Jenkins workspaces, manage disk usage, archive and publish build artifacts, and configure artifact retention policies.

Workspace Management and Build Artifacts

You'll learn: How Jenkins organizes build workspaces, manages disk space, and handles build artifacts to keep your CI/CD system efficient and tidy.

What Are Jenkins Workspaces?

Think of a Jenkins workspace like a temporary desk assigned to each project. When a build runs, Jenkins checks out your source code into this workspace directory on the build agent. Each job gets its own folder under JENKINS_HOME/workspace/ where it can compile code, run tests, and generate files.

The problem? Workspaces grow fast. Old build files, temporary data, and dependencies pile up, consuming disk space. If left unchecked, agents run out of storage and builds fail.

Managing Workspace Disk Usage

Jenkins provides tools to clean up workspaces:

  • Workspace Cleanup Plugin: Automatically deletes workspace contents before or after builds
  • Manual cleanup: Use build steps to remove unnecessary files with shell commands
  • Disk usage monitoring: Track which jobs consume the most space

Configure cleanup in your job's build settings to prevent disk bloat.

Build Artifacts: Saving What Matters

Not everything in the workspace matters long-term. Artifacts are the important outputs you want to preserve—compiled binaries, test reports, JAR files, deployment packages.

Instead of keeping entire workspaces, archive specific artifacts:

  • Configure Post-Build Actions to archive patterns like target/*.jar or dist/**/*
  • Jenkins stores archived artifacts separately from workspaces
  • Other jobs or users can download these artifacts later

Artifact Retention Policies

Storage isn't infinite. Set retention policies to automatically discard old artifacts:

  • Keep artifacts only from the last N builds
  • Discard artifacts older than X days
  • Keep artifacts from successful builds longer than failed ones

Configure these under "Discard Old Builds" in job settings to balance history with storage costs.

Key Takeaway: Proper workspace and artifact management prevents disk space issues while preserving important build outputs—clean aggressively, archive selectively, and set smart retention policies.