gpt4 book ai didi

nexus - 从 Nexus 3 清除旧版本

转载 作者:行者123 更新时间:2023-12-04 02:49:34 48 4
gpt4 key购买 nike

我使用 Nexus 3,我想删除我的旧版本。在 Nexus 2 中有一个名为 Remove Releases From Repository 的计划任务。 . Nexus 3 中似乎缺少此任务。

我们如何从 Nexus 3 中删除旧版本?

谢谢

最佳答案

自 nexus 3 发布以来,您可以将 groovy 脚本部署到 nexus 管理器。只需创建一个新的执行脚本任务并使用以下脚本:

import org.sonatype.nexus.repository.storage.StorageFacet;
import org.sonatype.nexus.common.app.GlobalComponentLookupHelper
import org.sonatype.nexus.repository.maintenance.MaintenanceService
import org.sonatype.nexus.repository.storage.ComponentMaintenance
import org.sonatype.nexus.repository.storage.Query;
import org.sonatype.nexus.script.plugin.RepositoryApi
import org.sonatype.nexus.script.plugin.internal.provisioning.RepositoryApiImpl
import com.google.common.collect.ImmutableList
import org.joda.time.DateTime;
import org.slf4j.Logger

// ----------------------------------------------------
// delete these rows when this script is added to nexus
RepositoryApiImpl repository = null;
Logger log = null;
GlobalComponentLookupHelper container = null;
// ----------------------------------------------------

def retentionDays = 30;
def retentionCount = 10;
def repositoryName = 'maven-releases';
def whitelist = ["org.javaee7.sample/javaee7-simple-sample", "org.javaee7.next/javaee7-another-sample"].toArray();


log.info(":::Cleanup script started!");
MaintenanceService service = container.lookup("org.sonatype.nexus.repository.maintenance.MaintenanceService");
def repo = repository.repositoryManager.get(repositoryName);
def tx = repo.facet(StorageFacet.class).txSupplier().get();
def components = null;
try {
tx.begin();
components = tx.browseComponents(tx.findBucket(repo));
}catch(Exception e){
log.info("Error: "+e);
}finally{
if(tx!=null)
tx.close();
}

if(components != null) {
def retentionDate = DateTime.now().minusDays(retentionDays).dayOfMonth().roundFloorCopy();
int deletedComponentCount = 0;
int compCount = 0;
def listOfComponents = ImmutableList.copyOf(components);
def previousComp = listOfComponents.head().group() + listOfComponents.head().name();
listOfComponents.reverseEach{comp ->
log.info("Processing Component - group: ${comp.group()}, ${comp.name()}, version: ${comp.version()}");
if(!whitelist.contains(comp.group()+"/"+comp.name())){
log.info("previous: ${previousComp}");
if(previousComp.equals(comp.group() + comp.name())) {
compCount++;
log.info("ComCount: ${compCount}, ReteCount: ${retentionCount}");
if (compCount > retentionCount) {
log.info("CompDate: ${comp.lastUpdated()} RetDate: ${retentionDate}");
if(comp.lastUpdated().isBefore(retentionDate)) {
log.info("compDate after retentionDate: ${comp.lastUpdated()} isAfter ${retentionDate}");
log.info("deleting ${comp.group()}, ${comp.name()}, version: ${comp.version()}");

// ------------------------------------------------
// uncomment to delete components and their assets
// service.deleteComponent(repo, comp);
// ------------------------------------------------

log.info("component deleted");
deletedComponentCount++;
}
}
} else {
compCount = 1;
previousComp = comp.group() + comp.name();
}
}else{
log.info("Component skipped: ${comp.group()} ${comp.name()}");
}
}

log.info("Deleted Component count: ${deletedComponentCount}");
}

https://github.com/xninjaxelitex/nexus3-cleanup-release-artifact

此脚本将通过顶部的指定参数清理您的 nexus 存储库。

关于nexus - 从 Nexus 3 清除旧版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40742766/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com