Tester101
Tester101

Reputation: 8172

Why does my Jenkins httpRequest plugin have no content?

I'm trying to send an httpRequest to an agent, to determine if it's online. The code from my pipeline looks like this.

@NonCPS
def isNodeOffline() {
    def response = httpRequest url: "http://jenkinsServer/computer/NodeName/api/json"
    def json = new groovy.json.JsonSlurper().parseText(response.content)
    return json.offline
}

From the stage, I'm calling the function, and printing the results.

def nodeOffline = isNodeOffline()
println("NodeOffline: "+nodeOffline)

However, when I run this code, the result is

NodeOffline: Status: 200

For some reason, the httpRequest is only returning the status. Am I doing something wrong?

Upvotes: 0

Views: 712

Answers (1)

Rich Duncan
Rich Duncan

Reputation: 1923

Take out the @NonCPS annotation. You can't call steps (httpRequest) in non-cps methods. Have a look at the docs on CPS - https://github.com/cloudbees/groovy-cps

Upvotes: 1

Related Questions