我们如何使用 curl 搜索 nexus repo 标签?
How do we search nexus repo tag using curl?
有谁知道如何在 nexus 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
但它 return 什么都没有。
当我使用浏览器界面时,我可以标记工件。
寻找此答案的人:
curl -u user:password -v -X GET https:///service/rest/v1/search?docker.imageTag=testTag31
编辑2:
这是从 docker 存储库中检索 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
}
有谁知道如何在 nexus 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
但它 return 什么都没有。 当我使用浏览器界面时,我可以标记工件。
寻找此答案的人:
curl -u user:password -v -X GET https:///service/rest/v1/search?docker.imageTag=testTag31
编辑2: 这是从 docker 存储库中检索 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
}