【问题标题】:Delete asset and component with groovy in Nexus Sonatype在 Nexus Sonatype 中使用 groovy 删除资产和组件
【发布时间】:2018-02-16 07:06:39
【问题描述】:

我们正在使用最新版本的 nexus,我想要创建一个清理任务。

我有一个 groovy 脚本,它在我从事务对象获得的可迭代组件列表上运行。

现在我想找到组件的资产,然后删除资产和组件。

我的脚本如下所示:

// Get a repository
def repo = repository.repositoryManager.get('maven-releases');
// Get a database transaction
def tx = repo.facet(StorageFacet).txSupplier().get();
// Begin the transaction
tx.begin();

def components = tx.browseComponents(tx.findBucket(repo));

// retention date
def retentionDate = new DateTime();
retentionDate.minusDays(1);

components.each{comp ->
    def lastComp = comp.group() + comp.name();
    def lastModDate = comp.lastUpdated();

    if(lastModDate.isBefore(retentionDate)) {
        // here -----------
        // tx.deleteAsset(<asset>)
        // -----------------
        tx.deleteComponent(comp);
        log.info("${lastComp} deleted!");
    }

    log.info("anz: ${assetCount} ${comp.version()} - ${lastModDate} - ${retentionDate}");
}

// End the transaction*/
tx.commit();

是否可以找到组件对应的资产?

【问题讨论】:

    标签: groovy nexus sonatype


    【解决方案1】:

    这很简单:

    Asset asset = tx.findAsset(comp.entityMetadata.getId(), tx.findBucket(repo));
    

    【讨论】:

      猜你喜欢
      • 2017-11-22
      • 2017-05-12
      • 2016-07-19
      • 1970-01-01
      • 2018-07-25
      • 2016-09-07
      • 2017-03-14
      • 2018-01-17
      • 2021-04-11
      相关资源
      最近更新 更多