2016-11-25 31 views
0

我正在使用作業DSL,我想下載文件,讀取它並設置一些env變量。使用作業DSL上的文件功能

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) 

} 

這是I'm接收

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

好像文件的不能被使用的功能除外。但在groovy文件中,我期望可以使用Job DSL模板以及所有常規功能。

回答

2

文件是空,因此拋出NPE,當你調用一個方法就可以了

def file 
... 
file.withOutputStream { // BANG! 
+0

哪裏是手掌表情圖標,當你需要它! – paul