我有Nexus3服务器,我在上面保存了工件,它已经填满到最大。我希望创建一个任务,每天删除旧的工件,但始终保留至少50个工件。问题是,默认任务应该做到这一点,但不起作用。


所以我读到它可以通过一个groovy脚本来完成,我计划在任务内部运行它。
有人能帮我吗?我在网上找不到任何有用的东西。
发布于 2018-06-28 03:09:31
根据@daniel-schröter的回答,您可以添加一个Scheduled Task,如下所示:
转到System -> Tasks并单击Create Task。创建脚本任务:

将语言设置为groovy,并复制此脚本以适应计划任务(您应该提供自己的修改,这只是一个示例):
import org.sonatype.nexus.repository.storage.Component
import org.sonatype.nexus.repository.storage.Query
import org.sonatype.nexus.repository.storage.StorageFacet
log.info("delete components for repository: my-repo")
def compInfo = { Component c -> "${c.group()}:${c.name()}:${c.version()}[${c.lastUpdated()}]}" }
def repo = repository.repositoryManager.get("my-repo")
StorageFacet storageFacet = repo.facet(StorageFacet)
def tx = storageFacet.txSupplier().get()
tx.begin()
Iterable<Component> components = tx.findComponents(Query.builder().where('last_updated < ').param('2190-01-01').build(), [repo])
tx.commit()
tx.close()
log.info("about to delete " + components.flatten(compInfo))
for(Component c : components) {
log.info("deleting " + compInfo(c))
tx2 = storageFacet.txSupplier().get()
tx2.begin()
tx2.deleteComponent(c)
tx2.commit()
tx2.close()
}
log.info("finished deleting " + components.flatten(compInfo))发布于 2017-10-05 20:06:57
我偶然发现了同样的问题。我真的认为这些特性应该是开箱即用的,但是删除旧发布的工件等任务在nexus中等待了很长时间。最后,我写了一些脚本来显示在哪个repo中存储了多少工件,以及每月存储了多少工件等。然后我写了一个脚本来删除旧的……您可能可以使用或扩展它:https://github.com/danischroeter/nexus-repo-scripting
https://stackoverflow.com/questions/45589937
复制相似问题