在 Jenkins 作業的“放棄舊構建”設定中,您可以輸入“保留構建的天數”和“保留構建的最大數量”的值。詹金斯如何回應擁有這兩個設定?它是只選擇一個,還是結合了行為,以便構建歷史必須比時間限制更舊并超過最大構建數量?
uj5u.com熱心網友回復:
Jenkins 日志輪換示例
考慮下面的例子
buildDiscarder(logRotator(daysToKeepStr: '30', numToKeepStr: '100'))
此日志輪換策略將在每次構建后運行,它將洗掉任何超過 100 的構建,以及任何超過 30 天的構建(即使構建少于 100 次)。Jenkins 將查看每個特定的構建,如果它僅滿足這些標準之一,它將被洗掉
偽代碼
if( build.age > 30 || build.number > 100 ) {
delete build
}
請記住,這將覆寫您配置的任何全域日志輪換設定
這是Jenkins 核心使用的LogRotator類。這是 Jenkins 用于執行日志輪換的確切代碼
if(numToKeep!=-1) {
// Note that RunList.size is deprecated, and indeed here we are loading all the builds of the job.
// However we would need to load the first numToKeep anyway, just to skip over them;
// and we would need to load the rest anyway, to delete them.
// (Using RunMap.headMap would not suffice, since we do not know if some recent builds have been deleted for other reasons,
// so simply subtracting numToKeep from the currently last build number might cause us to delete too many.)
RunList<? extends Run<?,?>> builds = job.getBuilds();
for (Run r : builds.subList(Math.min(builds.size(), numToKeep), builds.size())) {
if (shouldKeepRun(r, lsb, lstb)) {
continue;
}
LOGGER.log(FINE, "{0} is to be removed", r);
try { r.delete(); }
catch (IOException ex) { exceptionMap.computeIfAbsent(r, key -> new HashSet<>()).add(ex); }
}
}
if(daysToKeep!=-1) {
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_YEAR,-daysToKeep);
Run r = job.getFirstBuild();
while (r != null) {
if (tooNew(r, cal)) {
break;
}
if (!shouldKeepRun(r, lsb, lstb)) {
LOGGER.log(FINE, "{0} is to be removed", r);
try { r.delete(); }
catch (IOException ex) { exceptionMap.computeIfAbsent(r, key -> new HashSet<>()).add(ex); }
}
r = r.getNextBuild();
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/363208.html
標籤:詹金斯
上一篇:掌舵|JenkinsAzure密鑰保管庫機密以掩碼(********)的形式傳遞,因此在helm命令中不拋出任何值例外
下一篇:詹金斯:無法運行程式“/Users/user/.jenkins/workspace/jenkinsjob/taurus-venv/bin/bzterror=2
