12:40:37 File Create Operation:
12:40:37 Creating file: /root/.jenkins/workspace/CommonDevelop_shell/jenkinsBuildInfoPath/buildInfo.properties
12:40:37 File Properties To Json Operation:
12:40:37 ./jenkinsBuildInfoPath/buildInfo.properties file doesn't exists, the target file remains as is.
File Operations Plugin 在版本 1.11 上,Properties文件转json文件的时候,如果需要写入的json文件不存在的时候,会报错源文件不存在,这是个bug!
配置如下:
源码地址:
https://github.com/jenkinsci/file-operations-plugin/blob/master/src/main/java/sp/sd/fileoperations/FilePropertiesToJsonOperation.java
@Override
public Boolean invoke(File ws, VirtualChannel channel) {
boolean result = false;
try {
FilePath fpWS = new FilePath(ws);
FilePath fpSL = new FilePath(fpWS, resolvedSourceFile);
FilePath fpTL = new FilePath(fpWS, resolvedTargetFile);
if (!fpTL.exists()) {
listener.getLogger().println(resolvedSourceFile + " file doesn't exists, the target file remains as is.");
} else {
String fileContent = "";
Properties sourceProperties = new Properties();
sourceProperties.load(fpSL.read());
fpTL.write(convertToJson(sourceProperties), "UTF-8");
result = true;
listener.getLogger().println("Creating Json: from source " + fpSL.getRemote() + " to target " + fpTL.getRemote());
}
} catch (RuntimeException e) {
listener.fatalError(e.getMessage());
throw e;
} catch (Exception e) {
listener.fatalError(e.getMessage());
result = false;
}
return result;
}
查看源码可知,判断的是fpTL即写入的目标文件resolvedTargetFile不存在,抛出的异常是 resolvedSourceFile 不存在,牛头不对马嘴!!!
临时解决,可以先创建一个目标文件,如下:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)