Julian
Julian

Reputation: 1675

Jenkins HttpRequest plugin MissingMethodException

In my jenkins pipeline, I historically have invoked curl from the command line to make http requests, and I'm looking to streamline it.

I installed the HttpRequest plugin on my jenkins deployment, and I'm running a basic pipeline to test it out. However, when I run a snippet that I generated from the snippet generator, I get this exception.

groovy.lang.MissingMethodException: No signature of method: Script1.httpRequest() is applicable for argument types: (java.util.LinkedHashMap) values: [[authentication:myJenkinsAuth, url:https://api.github.com/repos/user/repo/commits/123456789/status]]

The line of code I'm using is:

def response = httpRequest authentication: 'myJenkinsAuth', contentType: 'APPLICATION_JSON', url: "https://api.github.com/repos/user/repo/commits/${commitSHA}/status"

The version of the HTTP Request Plugin I'm using is 1.8.22

I'm unsure why the method definition wouldn't be found, to my knowledge, this is exactly what the documentation is telling me I should do, which aligns with the snippet jenkins generated for me. Any insight would be appreciated. I can offer more info if I missed any useful details

Edit: I believe the job this is being run in is a freestyle job, and the actual code is being run inside a groovy postbuild step (in the post-build actions section)

Upvotes: 2

Views: 2737

Answers (1)

yoyomeng
yoyomeng

Reputation: 31

Took me awhile to realize my similar issue was a scoping problem. Not sure if you are calling httpRequest within a static method, but if so remove static.

MyScript.groovy:

static def myMethod() {
    httpRequest acceptType: 'APPLICATION_JSON',
                url: url,
                <...>
}

Gradle error:

groovy.lang.MissingMethodException: No signature of method: static MyScript.httpRequest() is applicable for argument types: (java.util.LinkedHashMap) values: [[<...>

It's looking for httpRequest within MyScript. Oops... Removing static worked.

Upvotes: 2

Related Questions