【发布时间】:2019-06-05 04:03:34
【问题描述】:
我正在集成 Squish 自动化工具和 Jenkins 管道。一切都很顺利。现在我需要在工作完成后发送电子邮件报告。我在预发送脚本中有一个 Groovy 文件,但是当这个脚本运行时,它会抛出异常:
java.lang.NullPointerException:无法在 null 对象上调用方法 getRootDir()
我发现我的 Groovy 脚本中的“构建”对象是 Null。不知道为什么。请注意,如果我在 Jenkins 上使用内置的 Squish 插件和可编辑电子邮件,一切都很顺利。当我转而使用 Pipeline 时,问题才发生。
@@@ - 这是我的 Groovy 脚本:
List getJenkinsTestResultFiles() {
File squishResultsPath = new File( build.getRootDir(), "squishResults" )
if ( !squishResultsPath.exists() || !squishResultsPath.isDirectory() ) {
throw new GroovyRuntimeException( "Squish results path does not exist at: " + squishResultsPath.getAbsolutePath() )
}
File summaryFile = new File( squishResultsPath, "summary.xml" )
if ( !summaryFile.exists() || !summaryFile.isFile() ) {
throw new GroovyRuntimeException( "Squish summary file does not exist at: " + summaryFile.getAbsolutePath() )
}
List resultFiles = []
def summaries = new XmlSlurper().parse( summaryFile )
summaries.summary.each {
resultFiles.push( new File( squishResultsPath, it.xmlFileName.text() ) )
}
return resultFiles
}
@@@ - 这是我的管道脚本:
node('Slave_10.133.88.151') {
stage('Squish Test') {
step([$class: 'SquishBuilder',
abortBuildOnError: false,
extraOptions: '',
host: '',
port: '',
resultFolder: "${WORKSPACE}\\Squish_Report",
skipTestCases: false,
snoozeFactor: '1',
squishConfig: 'Default',
testCase: '',
testSuite: "${WORKSPACE}\\${TEST_SUITE}"])
}
stage('Send Email') {
emailext body: 'Test',
postsendScript: '${SCRIPT, template="SquishSummary.groovy"}',
subject: 'Pipeline',
to: 'hoang@local.com'
}
}
【问题讨论】:
标签: jenkins jenkins-pipeline jenkins-groovy