Steps To Clean Jenkins Workspace
Step 1 : Go to Jenkins dashboard . Here create a sample freestyle project .
Step 2 : Now write a script which will generate some files in the workspace . (windows users should use windows batch commands and ubuntu users should use shell to write the script )
echo "hello geeks" > file1.txt
echo "Jenkins is easy" > file2.txt
echo "this is a sample job" > file3.txt
echo "this script is used in my w3wiki article"
Step 3 : Now after this build the project by selecting Build Now .
Step 4 : Select workspace to see the files .
Step 5 : Now to clean the workspace select Wipe Out Current Workspace and then click ok .
Now in your workspace you will not see any files . This workspace clean up should be done before performing any new build as to ensure that there is no conflict between present files and old files . Until now we have cleaned workspace manually , now follow the steps below to automate workspace clean up on each new build .
Step 6 : Select configure . Then go to a section called Build Environment . Here select Delete workspace before build starts .
From now, on each new build , the workspace is cleaned up . Basically all the files of old build are deleted .
Step 7 : Now update the script . Here i have only updated the file1.txt contents .
echo "hello geeks. This is an article on How to clean Jenkins Workspace " > file1.txt
echo "Jenkins is easy " > file2.txt
echo "this is a sample job" > file3.txt
echo "this script is used in my w3wiki article"
Step 8 : Now build the project and go to its workspace .
Step 9 : Now click on the file1.txt to see its content . You will see the updated content .
How To Clean Jenkins Workspace?
Jenkins is an open-source tool that is used to automate the build, test, and deploy stages of software. The Jenkins server always creates new workspaces on each new build to store the project code, build artifacts, log files, test files, and temporary files. Here in this guide, I will first discuss what is Jenkins. Then I will discuss Jenkins workspace and why it is important to clean Jenkins workspace. After this, i will guide you through the different steps to clean a Jenkins workspace of a particular Jenkins job.