Workspace cleanup
📖 Scenario: You are managing a Jenkins job that builds software projects. Over time, the workspace folder where Jenkins runs builds can fill up with old files. This can cause disk space issues and slow down builds.To keep the workspace clean, you want to add a step in your Jenkins pipeline to delete all files and folders in the workspace before starting a new build.
🎯 Goal: Build a Jenkins pipeline script that cleans the workspace folder at the start of the build using the deleteDir() command.
📋 What You'll Learn
Create a Jenkins pipeline script with a
pipeline blockAdd an
agent any directive to run on any available agentAdd a
stage named Cleanup WorkspaceInside the stage, use the
steps block to call deleteDir() to clean the workspacePrint a message
Workspace cleaned after cleanup💡 Why This Matters
🌍 Real World
Cleaning the workspace before builds prevents leftover files from previous builds causing errors or using too much disk space.
💼 Career
Jenkins pipeline scripting is a key skill for DevOps engineers to automate build and deployment processes reliably.
Progress0 / 4 steps