filters are not working on nexus3 extended choice paramter jenkins plugin

190 Views Asked by At

I am trying to fetch nexus latest builds as input paramters in jenkins,using nexus3 extended choice parameter for it,

my repository is raw repository hence does not contain groupid and artifactid.

I am able to fetch latest builds but only when I add groupid=* , artifactid=* and packaging=* but in this case i am getting sha1 files and md5 files also along with zip files,i need only zips here but when i add zip in packing text box it says (Working, but no Entries found)

i am expecting to get this filters working atleast packaging filter

1

There are 1 best solutions below

4
On

created a script for a similar use case, you can modify accordingly, i use this to populate an extended choice parameter:

import groovy.json.JsonSlurper
import hudson.model.*
import jenkins.model.*
Jenkins jenkins = Jenkins.getInstance()
import groovy.json.JsonSlurper
import com.cloudbees.plugins.credentials.CredentialsProvider
import com.cloudbees.plugins.credentials.domains.Domain
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder
import hudson.util.Secret

def cred = CredentialsProvider.lookupCredentials(
  com.cloudbees.plugins.credentials.common.StandardCredentials.class,
  Jenkins.instance,
  null
).find {
  it.id == "<CREDENTIALS_ID_HERE>"
}


def baseUrl = "https://<NEXUS_URL_HERE>/service/rest/v1"
def repository = "<REPO_NAME_HERE>"
def continuationToken = ""
def assets = []
def url = "${baseUrl}/search/assets?repository=${repository}"

while(true) {
    def get = new URL(url).openConnection()
    get.setRequestMethod("GET")
    get.setRequestProperty("Content-Type", "application/json")
    get.setRequestProperty("Authorization", "Basic ${cred.getSecret().getPlainText()}")
    def getRC = get.getResponseCode()
    def getResponse = get.getInputStream().getText()
    def finalresponse = new JsonSlurper().parseText(getResponse)

    if (finalresponse.items.path) {
        finalresponse.items.each { item ->
           
                assets.add([item.path])
            }
        }
    if(finalresponse.continuationToken) {
        continuationToken = finalresponse.continuationToken
        url = "${baseUrl}/search/assets?repository=${repository}&continuationToken=${continuationToken}"
    } else {
        break
    }
}
assets = assets.sort { a, b -> b[1].compareTo(a[1]) }.collect { it[0] }

return assets

P.S. Change placeholders accordingly. Please also go through the Nexus API documentation, and you can use postman to test it out for similar use cases.