curl - 我们如何使用 curl 搜索 nexus repo 标签?
问题描述
有谁知道如何在nexus repo中搜索某个标签?
我在我的 repo 中标记了一些工件和 docker 图像,我可以使用搜索找到它们:
我想使用命令行界面做同样的事情。
curl -u user:pwd -X GET https://nexus.acme.com/service/rest/v1/tags/testTag31
curl -u user:pwd -X GET https://nexus.acme.com/service/rest/v1/search/tags/testTag31
但它不返回任何东西。当我使用浏览器界面时,我可以标记工件。
解决方案
对于那些寻找这个答案的人:
curl -u user:password -v -X GET https:///service/rest/v1/search?docker.imageTag=testTag31
edit2:这是从 docker repo 中检索 docker 标签并找到绑定到该标签的所有 shas 的完整代码。然后对于找到的每个 sha,它会找到与该 sha 相关的所有工件。这是结果。如果需要,请随时更改它。我不是一个 groovy 专家,所以请随时发表评论以进行改进。
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
/*
Makes recursive call to handle the pagination
*/
def call(user, token, param, continuationToken, response, type, depth) {
//echo ' param =>' + param + ' continuationToken =>' + continuationToken +
' type =>'+ type + ' depth' + depth
def curlResponse
def parsedJson
switch (type) {
case 1: curlResponse = sh (script: "curl -u ${user}:${token} -sb GET https://nexus.hostname/service/rest/v1/search?docker.imageTag=${param}", returnStdout: true).trim()
break;
case 2: curlResponse = sh (script: "curl -u ${user}:${token} -sb GET https://nexus.hostname/service/rest/v1/search?docker.imageTag=${param}&continuationToken=${continuationToken}", returnStdout: true).trim()
break;
case 3: curlResponse = sh (script: "curl -u ${user}:${token} -sb GET https://nexus.hostname/service/rest/v1/search?sha1=${param}", returnStdout: true).trim()
break;
case 4: curlResponse = sh (script: "curl -u ${user}:${token} -sb GET https://nexus.hostname/service/rest/v1/search?sha1=${param}&continuationToken=${continuationToken}", returnStdout: true).trim()
break;
default:
echo 'invalid value '
break;
}
if (curlResponse == null) {
echo 'curlResponse is NULL'
return
}
parsedJson = new JsonSlurper().parseText(curlResponse)
if(depth ==1){
for (item in parsedJson.items){
response.add(item.assets.checksum.sha1)
if (parsedJson.continuationToken) {
curl(param,parsedJson.continuationToken,response,2,1)
}
}
}
if(depth ==2){
for (item in parsedJson.items){
if (response.get(item.name)== null) {
response.put(item.name,[])
}
response.get(item.name).add(item.version)
if (parsedJson.continuationToken) {
curl(param,parsedJson.continuationToken,response,4,2)
}
}
}
return response
}
return this
调用示例:
shas = listComponentsForTag(configs.nexusRegistry.credentialsId, configs.nexusRegistry.token,params.deliveryTag,"",shas,1,1)
for(sha in shas) {
componentsByVersion = listComponentsForTag(configs.nexusRegistry.credentialsId, configs.nexusRegistry.token, sha.getAt(0),"",componentsByVersion,3,2)
}
if (componentsByVersion.size() == 0) {
echo 'found no artifacts for tag provided'
}
echo 'found '+ componentsByVersion.size() + ' artifacts'
componentsByVersion.each{
echo ' Component => ' + it.key + ' versions =>' + it.value
}
推荐阅读
- arguments - Nim argv 等效项
- django - 使用 Multiselectfield 上的 django 过滤器后端进行过滤
- javascript - 如何在运行时了解已加载的 d3.js 扩展及其版本?
- python - 如何对返回相同类型的类实例的两个类实例(以 float 作为子类)执行算术运算?例如速度(2) + 速度(2)
- phpexcel - 使用php从数组中的对象(具有私有属性)访问值
- ruby-on-rails - 更新 gems,得到 NoMethodError: undefined method `[]' for nil:NilClass
- ruby - How to turn off topology change STDOUT logs on Mongoid
- laravel - Swift_TransportException 无法与主机 smtp.gmail.com 建立连接 [网络无法访问 #101]
- c# - 在数据库或 Visual Studio 上放置下拉菜单项以加快更新速度的最佳位置?
- powershell - 从 powershell 将类对象作为参数发送到 web api