paul paul - 1 year ago 89
Groovy Question

Use file features on Job DSL

I´m using Job DSL and I would like to download a file, read it, and set some env variables.

def static setSecrets(Job delegate, Map overrides = [:]) {
def liveUsername
def livePassword
def file
new URL('https://path/file').withInputStream { i ->
file.withOutputStream {
it << i
file.withReader { liveUsername = it.readLines().get(0) }
file.withReader { livePassword = it.readLines().get(1) }

def options = [
IDENTITY_USER: liveUsername,

setEnv(delegate, options, overrides)


This is the exception that I´m receiving

java.lang.NullPointerException: Cannot invoke method withOutputStream() on null object

Seems like the features of file cannot being used. But being in groovy file I was expecting can use the Job DSL templates and also, all the groovy features.

Answer Source

File is null so is throwing NPE when you call a method on it

def file
file.withOutputStream { // BANG!
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download