如何从詹金斯管道中的不同工作生成一份报告

时间:2019-03-04 11:27:54

标签: jenkins jenkins-pipeline

我想通过管道邮寄一份报告。执行不同作业的管道,每个作业都有报告。我正在查看“代码段生成器”,但无法设置乘法报告收集

1 个答案:

答案 0 :(得分:1)

好,所以首先假设您有工作A,工作B和工作C(分别称为工作A和工作B)

在每个作业A和作业B中,您都需要归档其日志文件,因此您需要将此脚本添加到管道中:

def jenkins = Jenkins.getInstance()
def job = jenkins.getItem(jobName)
def bld = job.getBuildByNumber(buildNumber)=
//use the method that suits you
bld.getLog(100) //number of lines to read
bld.getLogFile()
bld.getLogReader()

现在您的日志已存储在每个作业中,您可以在后期阶段转到Job C并使用copyArtifact插件复制已存档的日志 例如:

//copyArtifacts filter: 'logs.log', fingerprintArtifacts: true, projectName: 'pathtoyourjob/job A', selector: lastSuccessful(), target: 'temp1' 

//copyArtifacts filter: 'logs.log', fingerprintArtifacts: true, projectName: 'pathtoyourjob/job B', selector: lastSuccessful(), target: 'temp1' 

这是我以前只能使用的解决方法。 希望对您有帮助!