I'm trying to make HTTP request from Active Choices Reactive Parameter
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
filterLength: 1,
filterable: true,
name: 'HTTP_TEST',
referencedParameters: '',
script: [$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script: 'return ["ERROR"]'
],
script: [
classpath: [],
sandbox: true,
script: """
def url = "https://example.com/api/v1"
def credentialsId = 'mycredential'
try {
// Make HTTP request
def response = httpRequest authentication: credentialsId, url: url
return [response.status]
} catch (Exception e) {
// handle exceptions like timeout, connection errors, etc.
return [e.toString()]
}
""".stripIndent()
]
]
],
but get error
groovy.lang.MissingMethodException: No signature of method: Script1.httpRequest() is applicable for argument types: (java.util.LinkedHashMap) values: [[authentication:mycredential, url:https://example.com/api/v1]]
I also tried HttpURLConnection
but it doesn't take Jenkins credentials (or I don't know how).
So, is it possible to call httpRequest
from parameter script?