Jenkins:ExtendedChoice参数-groovy-如何在主机上创建文件
我在“extended choice parameter”插件的groovy脚本部分定义了一个json字符串。此外,我想在groovy脚本区域内的主控端的一个文件中编写json配置。我想,也许工作目录是最好的地方Jenkins:ExtendedChoice参数-groovy-如何在主机上创建文件,groovy,jenkins,Groovy,Jenkins,我在“extended choice parameter”插件的groovy脚本部分定义了一个json字符串。此外,我想在groovy脚本区域内的主控端的一个文件中编写json配置。我想,也许工作目录是最好的地方 http://hudson/hudson/job/MY_JOB/config.json 如果你现在问,我为什么要这样做;背后的原因是,我不希望配置预先保存在其他地方。我不喜欢在作业配置之外配置文件。我想在作业配置中的一个位置查看/调整配置 我需要json配置中的许多其他信息,以便稍后
http://hudson/hudson/job/MY_JOB/config.json
如果你现在问,我为什么要这样做;背后的原因是,我不希望配置预先保存在其他地方。我不喜欢在作业配置之外配置文件。我想在作业配置中的一个位置查看/调整配置
我需要json配置中的许多其他信息,以便稍后在同一作业中的python代码部分中使用
我的问题是:
def filename = "config.json"
def targetFile = new File(filename)
if (targetFile.createNewFile()) {
println "Successfully created file $targetFile"
} else {
println "Failed to create file $targetFile"
}
- 我走错路了吗?有什么建议吗
- 我可以直接在主机端编写json配置吗?它不一定是詹金斯的工作目录。我不关心设备/目录
- 如果这个方法是可以接受的,我怎么做
def filename = "config.json"
def targetFile = new File(filename)
if (targetFile.createNewFile()) {
println "Successfully created file $targetFile"
} else {
println "Failed to create file $targetFile"
}
备注:
def filename = "config.json"
def targetFile = new File(filename)
if (targetFile.createNewFile()) {
println "Successfully created file $targetFile"
} else {
println "Failed to create file $targetFile"
}
文件路径看起来很有趣
谢谢你的帮助,西蒙我明白了:
import groovy.json.*
// location on the master : /srv/raid1/hudson/jobs
jsonConfigFile = new File("/srv/raid1/hudson/jobs/MY_JOB/config.json")
jsonConfigFileOnMaster = new hudson.FilePath( jsonConfigFile )
if( jsonConfigFileOnMaster.exists() ){
jsonConfigFileOnMaster.delete()
}
jsonConfigFileOnMaster.touch( System.nanoTime())
jsonFormatted = JsonOutput.toJson( localJsonString )
jsonConfigFile.write jsonFormatted