OSS Nexus 3 - 链接到最新版本的工件

问题描述 投票:1回答:1

我正在构建jenkins的工件,并在每次git提交时通过nexusArtifactUploader将它们上传到OSS Nexus 3.6中的maven2 repo。在标记的提交上,它上传为git tag中提到的版本的发布;未标记的提交作为最后一个git标签版本的快照发布。

每个人都有对该存储库的RO访问权限,因此我无需指定任何凭据即可下载该工件。

在部署阶段,我通过nexus_url / repository / my-repo-releases / com / example / somthing / my_artifact / 1.0.15 / my_artifact-1.0.15.jar等链接下载工件。但是我想通过nexus_url / repository / my-repo-releases / com / example / something / my_artifact / latest这样的链接下载最新版本(我不想指定版本号,我只想拥有最新版本)。

你能告诉我怎么做吗?它看起来像每个存储库的基本操作。我不确定是否应该使用nexus API编写一些脚本 - 或者shell I?

nexus nexus3
1个回答
0
投票

目前,Nexus 3并未提供Nexus 2中的“最新”功能。它仅提供简单的REST API。

我用Python脚本做到了这一点。您必须查询的URL如下所示:

request_url = nexus_url + "/service/siesta/rest/v1/assets?repositoryId=" + repository_id

在响应中,您将收到包含下载URL,其他属性和延续令牌的工件的5个随机条目。因此,您可以使用延续令牌遍历所有工件(虽然存在延续令牌)。

request_url = nexus_url + "/service/siesta/rest/v1/assets?continuationToken=" + response["continuationToken"] + "&repositoryId=" + repository_id

从downloadURL中提取工件版本,将此版本保存到OrderedDictionary,获取最高工件编号(最大值)并使用其下载URL:

od = collections.OrderedDict(sorted(all_download_urls.items()))
download_key = max(od)

if bool(max(od)):
    download_url = od.get(download_key)

    print "Downloading this version: "
    print download_key
    print "---------------------------"
    print "Using this download url"
    print download_url
    os.system("wget %s --user=%s --password=%s" % (download_url, user, password))
else:
    print "Not found."

说实话,我真的不知道为什么Sonatype在没有“最新”功能的情况下发布了Nexus3 ......

编辑

我为Nexus 3.3.x编写了这个脚本,所以在3.6中,从REST调用返回的URL或属性可能略有不同。

© www.soinside.com 2019 - 2024. All rights reserved.