Nexus3 только 50 загрузок в списке - PullRequest
0 голосов
/ 18 июня 2019

Итак, у меня есть код, который загружает номер версии каждого пакета nuget, но все останавливается после 50 в списке.

Я использую jenkins с отличным кодом и получаю список версий.

import groovy.json.JsonSlurperClassic 
import groovy.json.JsonBuilder
import wslite.rest.*


 def data = new URL("http://nexus.xx.xx.se:8081/service/rest/v1/search?repository=xx-sx-nuget&name=XXXFrontend").getText()  
 println data


/**
 * 'jsonString' is the input json you have shown
 * parse it and store it in collection
 */
 Map convertedJSONMap = new JsonSlurperClassic().parseText(data)


//If you have the nodes then fetch the first one only
if(convertedJSONMap."items"){

     println "Version : " + convertedJSONMap."items"[0]."version"
 }   

def list = convertedJSONMap.items.version
Collections.sort(list)


list

Так что проблема в том, что он получает только 50 версий.Как я могу получить больше 50?Я читал о continuetoken, но я не понимаю, как его использовать?


ОБНОВЛЕНИЕ

Я добавил это, но все еще не работает

while(convertedJSONMap."continuesToken" != null){
def token =  convertedJSONMap."continuationToken"
def data2 = new URL("http://nexus.xxx.xxx.se:8081/service/rest/v1/search?repository=xxx-xx-nuget&name=xxxxxx&continuationToken=" +token).getText() 
 convertedJSONMap = JsonSlurperClassic().parseText(data2)

}

1 Ответ

0 голосов
/ 08 июля 2019

Вот как я решил это для себя.Это просто фрагмент кода, который я использую

def json = sendRequest(url)

addResultToMap(map2, json, release) //I do something here with the received result

def continuationToken = json.continuationToken
if (continuationToken != null) {
    while (continuationToken != null) {
        json = sendRequest(url + "&continuationToken=" + continuationToken)
        addResultToMap(map2, json, release) //I do something here with the received result as above
        continuationToken = json.continuationToken
    }
}

И мой метод sendRequest выглядит следующим образом

def sendRequest(def url, String method = "GET") {
    String userPass = "${nexus.username}:${nexus.password}"
    String basicAuth = "Basic " + "${printBase64Binary(userPass.getBytes())}"

    def connection = new URL( url ).openConnection() as HttpURLConnection
    connection.setRequestProperty('Accept', 'application/json' )
    connection.setRequestProperty('Authorization', basicAuth)
    connection.setRequestMethod(method)

    try {
        if ( connection.responseCode <= 299 ) {
            if (connection.responseCode == 200) {
                return connection.inputStream.withCloseable { inStream -> new JsonSlurper().parse( inStream as InputStream ) }
            }
        } else {
            displayAndLogError(connection.responseCode + ": " + connection.inputStream.text, loglevel.DEBUG)
        }
    } catch(Exception exc) {
        displayAndLogError(exc.getMessage())
    }
}
...