我创建了一个复杂的管道。在每个阶段我都称之为工作。我想查看 Jenkins 某个阶段中每个作业的控制台输出。如何获得?
从构建步骤返回的对象可用于查询日志,如下所示:
pipeline {
agent any
stages {
stage('test') {
steps {
echo 'Building anotherJob and getting the log'
script {
def bRun = build 'anotherJob'
echo 'last 100 lines of BuildB'
for(String line : bRun.getRawBuild().getLog(100)){
echo line
}
}
}
}
}
}
从构建步骤返回的对象是运行包装器 https://github.com/jenkinsci/workflow-support-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.java类对象。 getRawBuild() 调用返回一个Run https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/model/Run.javaobject - 除了从此类的外观中逐行读取日志之外,可能还有其他选项。为此,您需要禁用管道沙箱或获得这些方法的脚本批准:
method hudson.model.Run getLog int
method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild
如果您要为许多构建执行此操作,则值得将一些代码放入管道共享库中以执行您需要的操作或在管道中定义函数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)