Search code examples
jenkinsspacedisk

Jenkins: remove repo after build, keep only log


Jenkins is checking out my projects' repositories every time for each build and each PR. This quickly fills up the disk (only 10Gb) as each checkout amounts to 300Mb and there are 5 projects (all in range of 300-500Mb per project). We've already set Discard old items with empty values but it doesn't seem to delete the files once the PR has another build.

I've noticed the files are stored at: /data/versioning/config/jobs/MyProjectAbc/branches/PR-9424/workspace@script/ Is there an option for Jenkins to delete the whole PR-xxxx/workspace@script folder and only keep the PR-xxxx/builds folder?

Lightweight checkouts currently aren't possible (possibly because of outdated plugin, Bitbucket Branch Source 2.2.8)


Solution

  • You could use the Workspace Cleanup Plugin as a post-step in your pipeline to clear out the workspace after each build.

    Something like:

    pipeline {
        post {
            always {
                cleanWs()
            }
        }
    }