0

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?

Marat Gareev
  • 387
  • 1
  • 4
  • 16
  • Maybe try [REST List Parameter](https://plugins.jenkins.io/rest-list-parameter/) plugin? – Ian W Aug 31 '21 at 04:27
  • @IanW interesting plugin, thanks! But looks like it doesn't suit because I have to process response and form resulting list. – Marat Gareev Aug 31 '21 at 08:59

0 Answers0