I have the next Groovy code which I try to run in Jenkins Pipeline:
@Grab('io.github.http-builder-ng:http-builder-ng-core:1.0.3')
import static groovyx.net.http.HttpBuilder.configure
def astros = configure {
request.uri = 'http://api.open-notify.org/astros.json'
}.get()
println "There are ${astros.number} astronauts in space right now."
astros.people.each { p->
println " - ${p.name} (${p.craft})"
}
But everytime I get java.lang.NullPointerException: Cannot invoke method get() on null object error.
When I run it from my desktop, everything works as expected:
There are 6 astronauts in space right now.
In Jenkins:
There are null astronauts in space right now.
Debug output:
<groovyx.net.http.UriBuilder$Basic@4bc2413c scheme=http port=-1 host=api.open-notify.org path=/astros.json query=[:] fragment=null userInfo=null parent=groovyx.net.http.UriBuilder$ThreadSafe@69c6847a useRawValues=null>
What should I do to make it work?