在下载工件之前,如何从用户插件检查构建信息?

问题描述

我们要防止在我们的本地Artifactory安装中使用用户插件来下载没有构建信息的工件。我们正在努力寻找Request和相应的BuildInfo之间的连接。

import org.artifactory.request.Request
import org.artifactory.repo.RepoPath

download {
    beforeDownloadRequest { Request request,RepoPath repoPath ->
        if (isRelease(repoPath.repoKey)) {
            log.warn "Is a release artifact"
            // How to verify build info here??
        }
    }
}

def isRelease(String repoKey) {
    return repoKey in ["libs-release-local"]
}

解决方法

使用Artifactory查询语言,您可以找到基于工件的内部版本,如果结果为空,则没有这样的内部版本:https://www.jfrog.com/confluence/display/JFROG/Artifactory+Query+Language

例如: builds.find({“ module.artifact.item.name”:“ artifactory.war”})

链接到构建的工件也将具有属性“ build.number”和“ build.name”,因此这是一种处理方法

正确的解决方案是使用JFrog Xray。然后,您可以对构建进行扫描,以便对构建中的所有工件进行扫描(此外,您还将在那里进行安全性和许可证合规性检查),然后阻止未扫描的工件的下载

最后,当您创建构建时,您也可以将其升级,例如从“登台”升级为“发布”,然后在该操作上将工件复制或移动到仅是构建发行的存储库中。

“ build.name”和“ build.number”属性可能是您尝试执行操作的最佳方法。