Reputation: 8172
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
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