如何将jenkins插件导入上次成功构建工件报告到当前构建
我写了一个插件如下 并生成一个html报告如何将jenkins插件导入上次成功构建工件报告到当前构建,jenkins,groovy,Jenkins,Groovy,我写了一个插件如下 并生成一个html报告 File artifactsDir = build.getArtifactsDir(); String path = artifactsDir.getCanonicalPath() + REPORT_TEMPLATE_PATH; File reportFile = new File("path"); // write report's text to th
File artifactsDir = build.getArtifactsDir();
String path = artifactsDir.getCanonicalPath() + REPORT_TEMPLATE_PATH;
File reportFile = new File("path");
// write report's text to the report's file
对于下一个构建,我想导入此报告文件以查看更改
我试过这些,但都不管用
build.getPreviousSuccessfulBuild().getArtifactManager().root() + REPORT_TEMPLATE_PATH
// fail with File not found, but the file is there in bash
build.getPreviousSuccessfulBuild().getArtifactsDir() + REPORT_TEMPLATE_PATH
// null pointer exception, seems to be generated by getArtifactsDir()
build.getPreviousBuild().getArtifactManager().root() + REPORT_TEMPLATE_PATH
那么,如何在当前构建中获得最后一个成功的构建报告文件呢?这就是我在管道作业中如何做到的。我剥离了部分原始代码,希望没有引入错误。为了清晰起见,我还删除了错误处理:
//查找上次成功的生成
def lastSuccessfulBuild=currentBuild.getPreviousBuild()
而(lastSuccessfulBuild&(lastSuccessfulBuild.currentResult!='SUCCESS')){
lastSuccessfulBuild=lastSuccessfulBuild.getPreviousBuild()
}
//我在这里查找一个名为“crc.txt”的文件
//只有当您有一个
//archiveArtifacts工件:“crc.txt”,指纹:true
//在你身体的某个地方
def build=lastSuccessfulBuild?.getRawBuild()
def artifact=build.getArtifacts().find{it.fileName=='crc.txt'}
def uri=build.artifactManager.root().child(artifact.relativePath.toURI())
def content=uri.toURL().text
当我比较我们的解决方案时:您不使用child()
,您在REPORT\u TEMPLATE\u path
中有相对路径,而我从工件获取它