2016-11-25 34 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