编辑后未保存存储库中的本地文件(groovy/jenkins)



在我的Jenkins工作中,我签出了一个存储库。在这个repo中,有一个文件,我想在工作期间编辑它。但文件似乎没有保存。我有一个这样的方法:

def updateFile(id, key){
def inputFile = readFile("${workspace}/config/cnf.json")
def inputJSON = new JsonSlurper().parseText(inputFile)
inputJSON."${key}"[0].pref = "${id}"
def result = JsonOutput.toJson(inputJSON)
//here it is changed.
println "result:n${result}"
inputFile << "${JsonOutput.prettyPrint(result)}"
//and now it is again the old one.
println "Hier: n ${inputFile}"
}

问题是,我不能使用"new File"one_answers".write"或".append",因为Jenkins找不到这样的文件。

def inputFile = new File("${workspace}/config/cnf.json") --> no File found

是否有保存现有文件的好方法?

如果readFile("${workspace}/config/cnf.json")工作良好

然后使用writeFile写入文件,如下所示:

writeFile file:"${workspace}/config/cnf.json", text:result

最新更新