0

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,
            IDENTITY_PASSWORD: livePassword]

    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.

paul
  • 12,873
  • 23
  • 91
  • 153

1 Answers1

2

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

def file
...
file.withOutputStream { // BANG!
lance-java
  • 25,497
  • 4
  • 59
  • 101