我有nexus 3服务器,我在上面保存了工件,它已经被填满了。我希望每天创建一个删除旧工件的任务,但始终保留至少 50 个工件。问题是应该执行的默认任务不起作用。
所以我读到它可以使用我安排在任务内部运行的 groovy 脚本来完成。
有人可以帮我吗?我在互联网上找不到任何有用的东西。
根据@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))
我偶然发现了同样的问题。我真的认为这些功能应该是开箱即用的,但是删除旧发布的工件等的任务只是等待连接积压的时间。最后我写了一些脚本来显示在哪个仓库中存储了多少工件以及每月有多少等。然后我写了一个脚本来删除旧的......你可能可以使用或扩展这个: https://github。 com/danischroeter/nexus-repo-scripting