0

我想做的是这样的:

  • 构建并将应用程序/包推送到工件
  • 部署该工件(不使用 jfrog 管道)
  • 部署后将元数据(自定义属性集)添加到已部署的工件,其中包括诸如何时部署、部署失败或成功时部署在何处以及诸如“LatestDeploymentAttempt:true|false”之类的信息)
  • 构建一个脚本/仪表板以列出所有已部署的工件和元数据

所有这些都是可行的,但我有一个关于如何实现LatestDeploymentAttempt:true属性的问题

我想要的是一种行为,我可以将属性应用于工件,并立即从该工件的所有其他版本中删除相同的属性。因此,我可以在工件版本中添加像 LatestDeploymentAttempt: true 这样的属性,并且 jfrog 会自动从该包的所有其他版本中删除 LatestDeploymentAttempt 属性 - 如果我可以过滤单个属性,这将使列出部署的版本更容易

这可能吗?

如果有办法使用 REST API 说“从所有版本中删除此属性”,我可以在将其添加到已部署的工件之前手动删除它,但如果 jfrog 有某种内置的做事方式,那就太好了这个。

4

1 回答 1

0

您可以通过使用or事件回调实现用户插件来实现此目的。 该插件可以使用Artifactory 公共 API来搜索已经使用AQL(Artifctory Query Language)或property标记了此属性的工件。 您可以在 JFrog GitHub 用户插件存储库中找到 Artifactory 用户插件的示例。beforePropertyCreateafterPropertyCreate

这是此类插件的基本示例:

import org.artifactory.repo.RepoPath
import org.artifactory.search.aql.AqlResult
import org.artifactory.repo.RepoPathFactory
import java.util.Map

storage {
    beforePropertyCreate { item, name, values ->
        if (name == 'LatestDeploymentAttempt') {
            String aqlQuery = 'items.find({"$and" : [{"repo" : "my-repo-local"}, {"@LatestDeploymentAttempt" : {"$eq" : "true"}}]})'
            searches.aql(aqlQuery) { AqlResult result ->
                result.each { Map artifact ->
                    String itemPath = artifact.path + "/" + artifact.name
                    RepoPath repoPath = RepoPathFactory.create(artifact.repo, itemPath)
                    repositories.deleteProperty(repoPath, 'LatestDeploymentAttempt')
                }
            }
        }
    }
}
于 2021-01-07T10:33:08.913 回答