Improve Jenkins build (artefacts) retention
Currently, we configure:
buildDiscarder(logRotator(numToKeepStr: '5'))
Note that:
- The 5 most recent builds are thus kept.
- Each branch, merge request and tag is automatically detected and built as a separate sub-project in the multi-branch pipeline project. Thus, they each get to keep their 5 most recent builds.
- For each build also the built artefacts are kept.
However, what we want may depend on the branch etc:
-
master: We keep the last 5 most recent
master
builds and all their artefacts. However, they are also released, meaning they are both on the downloads server and on the build server. Furthermore,master
builds are to validate only, as the real release happens via a build of a release tag. -
develop: With regular development,
develop
builds gets removed quite frequently. It seems OK to have the current configuration there. If the latest one fails we want to still be able to download the latest successfully built product from a previous one. - other branches / merge requests: Branches and merge requests are typically short lived. They disappear quickly and thus it is OK to keep the current settings. However, for stale ones, we may want to remove some things (builds or just the artefacts) after a while.
- tags: We use tags for releases. These include the actual deployment. Once built and deployed, these tags never disappear, and thus the builds never disappear. I think that if we keep them for 4 months, and given our 3-month release schedule, that should be sufficient. These duplicate the actually released data on the download server.
There are 4 settings that we can configure (see docs: https://plugins.jenkins.io/build-discarder/):
artifactDaysToKeepStr
artifactNumToKeepStr
daysToKeepStr
numToKeepStr
We can thus configure the builds to keep separately from the artefacts of those builds to keep. We can also configure it based on the number of builds, the age of the builds, or both.
Furthermore, we can not only used fixed values, but also expressions, to configure these 4 settings based on e.g. the branch. The following example is taken from https://issues.jenkins.io/browse/JENKINS-47717?focusedCommentId=372160&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-372160:
numToKeepStr: env.BRANCH_NAME ==~ /master/ ? '100' :
env.BRANCH_NAME ==~ /production|test/ ? '10' :
env.BRANCH_NAME ==~ /feature\/.*|bug\/.*/ ? '5' : '1',
I propose the following settings:
- master: keep last 5 builds including artefacts, for maximum of 1 week (7 days)
- develop: keep last 5 builds including artefacts, regardless of age
- other branches / merge requests: keep last 5 builds including artefacts, for maximum of 1 month (30 days)
- tags: keep last 5 builds, for maximum of 4 months (120 days), but artefacts only for maximum 1 month (30 days)