Search code examples
jenkinsbuilddirectoryarchive

Is the archive directory in Jenkins saved even if I set Max # of builds to keep to a number?


I'm trying to understand the purpose of the archive directory. From what I've seen, the archive is per build. Meaning if I set the 'Max # of builds to keep' to 3 for example, The archive will also be deleted.

Is that correct?

If so, how can I tell Jenkins to only save my artifact (zip file) created and delete the build directory?

Is there a one archive directory for all builds?


Solution

  • There are two directories for a Jenkins job, by default (there can be just one, builds, in case of a Workflow job, or more, e.g. an additional promotions directory):

    • JENKINS_HOME/jobs/${JOB_NAME}/builds/ containing sub-dirs according to $BUILD_ID
    • JENKINS_HOME/jobs/${JOB_NAME}/workspace/

    So, there's one workspace per job and one build directory per build.


    Don't let the page Administering Jenkins with this change driven by JENKINS-8446 confuse you. The workspace default, as also mentioned in the inline help (of the current v1.635 at the time of this writing), is still:

    Manage Jenkins → Configure System → Advanced... → Workspace Root Directory: ${ITEM_ROOTDIR}/workspace

    It's NOT ${JENKINS_HOME}/workspace/${JOB_NAME}.


    If a discard of old builds takes place the workspace isn't discarded, but, since it exists per job, it is overwritten with every new build. Hence, if you'd like to keep old artifacts you can:

    • create an "archive" job that uses the Copy Artifact Plugin and connect it as downstream to your build job.
    • move them to some other location yourself (including creation of uniquely-named sub-dirs to store the artifact(s) in) using a Post-build ActionGroovy Postbuild or → Execute a set of scripts.

    There's also the Discard Old Build plugin which enhances Jenkins' built-in discard functionality via a Post-build Action.