Skip to main content

How to populate Choice Parameter with artifact information using Nexus REST API?

Comments

10 comments

  • Buddi Hemanthkumar

    Hi i tried this procedure , got an exception. Really appreciate your help on this. 

    and we have groupid,artifactid,version as well. 

     

    Failed to execute script

    java.io.FileNotFoundException: https://nexus.com/mother/content/repositories/snapshots/search?g=com.aper.rims&a=rims-scheduler&r=releases&p=xml
    0
  • Denys Digtiar

    Hi Buddi,

    The fetching of the URL content failed. The path section is wrong. You need to figure out if you are using the right URL. You can try to open it in the browser to see if it resolves to the expected thing. If it does, it is likely that your local environment is different from Jenkins, e.g. corporate DNS or Proxy servers.

    0
  • Buddi Hemanthkumar

    Hi,

    Denys Digtiar 

     

    Thanks for reply, Am able to fix the issue, and am able to populate the artifacts in choice parameter.

    I have other question, script worked fine with maven files, but i have other repository with .7z files , can you please help me to populate those files to choice parameter 

     

     

    Example : groupid- 

    groupid- com.apri.portfolio
    artifactid- pt-ap
    version: 17.01


    0
  • Tigran Mnatsakanyan

    Hi guys, is there an easy way to modify the "Accept" header to use application/json and configure basic authentication for the rest call below?

    $YOUR_NEXUS_URL.toURL().text

    Seems like the httpBuilder is not available within pipeline and i could not find toUrl() examples with custom hearders and basic auth.

     

    1
  • Vijay Deshmukh

    I altered the URL to suit our needs and it just does not work. When i checked the network traffic in chrome i see in most cases the url includes "service/extdirect" and do not see the "service/local/lucene". Should it not be the same? I am using Repo Manager Nexus 3.x

    0
  • Jennifer Heraty

    Hello. Very well written article which I wish I'd found 4 days ago because I've done the exact same thing but it took me forever. But I'm getting an unexpected error when I use the "Run the Script Now" button which begins: 

    java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)

    And I don't understand how SSL has anything to do with this. I do NOT get this error when I try to run this on my local machine from my IDE. Any ideas?
    Thanks!
    0
  • Allan Burdajewicz

    @Tigran To set the authentication, you can add it in the URL like https://$USER:$PASS@my.nexus.com. For setting the header, you need to use an object of type URLConnection. I believe the way to do this is to use the method URLConnection#setRequestProperty or maybe a HttpURLConnection object:

    myUrlConnection.setRequestProperty("Content-Type", "application/json")
    myUrlConnection.setRequestProperty("Authorization", "Basic ${new String(hudson.remoting.Base64.encode(url.getUserInfo().getBytes()))}")

    Note that if you are using Jenkins Pipeline, we recommend using sh / bat steps with curl and then to parse/read the JSON you can use the readJSON step.

    ----

    @Vijay The lucene/search endpoint is an official REST API. I am not sure about service/extdirect, it seems to be an internal module for Nexus.

    ----

    @Jennifer If you access your Nexus via HTTPS from Jenkins, you need to make sure that the process running the command (Jankins or the Jenkins agent) has the required SSL certificate. See How to install a new SSL Certificate

    ----

    Should you have any problem, please file a support request.

    0
  • Jeffry Hesse

    Hi there,

    To my knowledge this will not work with Nexus Repository 3. Do you mind updating your article to make this clear that it's intended currently for use with Nexus Repository 2? 

    Thanks!

    Sonatype Community Nerd

    0
  • Max Wahler

    I can only agree with Jeffry, that endpoint is not supported by Nexus 3. 

    An alternative plugin is https://wiki.jenkins.io/display/JENKINS/Maven+Metadata+Plugin 

    0
  • Kishoreredlapalli Please Update

    Do we have something similar for JFrog?

    0

Please sign in to leave a comment.

About CloudBees Support

Our Support Engineers are available to help with any questions or problems you may have with any of our products.