Issue with HTTPRequest Jenkins Plugin in JenkinsFile for Deleting Nexus Components via API - Sonatype Nexus Repository - Sonatype Community

Issue with HTTPRequest Jenkins Plugin in JenkinsFile for Deleting Nexus Components via API

Hi everyone,

I’m trying to delete components in Nexus using the httpRequest plugin in a Jenkins pipeline. The deletion works — the component gets deleted from Nexus — but I never receive the expected 204 No Content response. Instead, I encounter an error: groovy.json.internal.LazyMap.

Below is my code snippet:

def deleteResponse = httpRequest(
    url: "${env.NEXUS_URL}/service/rest/v1/components/${componentId}",
    httpMode: 'DELETE',
    authentication: 'nexus_credentials',
    customHeaders: [
        [name: 'accept', value: 'application/json'],
        [name: 'Content-Type', value: 'application/json']
    ],
    validResponseCodes: '100:599',
    responseHandle: 'NONE'
)

echo "HTTP Response Status: ${deleteResponse.status}"

The pipeline never reaches the echo line after the httpRequest call. To test, I wrapped the code in a try-catch block, which allowed it to proceed, but that’s not how I’d prefer to handle this.

Details:

Question:

Has anyone experienced a similar issue? If so:

  1. How did you handle the httpRequest response to avoid the error?
  2. Is there a configuration or workaround that ensures proper handling of the 204 response (or no response body)?

Thanks in advance for your help!


I suspect you may have a syntax error which either prevents the outbound call, or breaks the internal handling of the plugin you’re using.


Hi @mpiggott, thank you for your answer. I tried so many different combinations already and all lead the same, the component is deleted but it gives error in the request call =(. For now, it is in a try-catch until I can find a solution.


If you haven’t, try printing the stack trace of the error - the Jenkins source code is generally public so you may be able to track down the cause.


I had the same issue, try this:

import groovy.json.JsonSlurperClassic

@NonCPS
def jsonParse(def json) {
    new groovy.json.JsonSlurperClassic().parseText(json)
}