使用Jenkins测试工具时,如何查看被测试内容引发的实际错误?

时间:2020-07-20 15:18:39

标签: jenkins groovy spock jenkins-groovy jenkins-job-dsl

我正在尝试使用jenkins测试工具:https://github.com/jenkinsci/jenkins-test-harness

在此使用以下示例:https://github.com/testcookbook/jenkins_harness

当我的常规脚本失败但我看不到实际错误是什么

我在build.gradle中设置了testLogging.showStandardStreams true

例如:

# https://github.com/testcookbook/jenkins_harness/blob/master/jobs/Example1.groovy
freeStyleJob('Example1') {
    steps {
        shell('ls')
    }
}
# I dont have the folder plugin installed as a dependency so this will fail
folder('myfolder') {
    displayName('sdsdfsdf')
    description('testing')
}

我无法确定输出为什么/为什么失败,这就是我所看到的:

test script Example1.groovy FAILED
    org.spockframework.runtime.UnallowedExceptionThrownError at JobScriptsSpec.groovy:32
        Caused by: javaposse.jobdsl.dsl.DslScriptException at JobScriptsSpec.groovy:25

JobScriptsSpec STANDARD_ERROR
       8.898 [id=17]    INFO    jenkins.model.Jenkins#cleanUp: Stopping Jenkins

JobScriptsSpec STANDARD_OUT
    WARN: The method class org.apache.commons.logging.impl.SLF4JLogFactory#release() was invoked.
    WARN: Please see http://www.slf4j.org/codes.html#release for an explanation.
    WARN: The method class org.apache.commons.logging.impl.SLF4JLogFactory#release() was invoked.
    WARN: Please see http://www.slf4j.org/codes.html#release for an explanation.

JobScriptsSpec STANDARD_ERROR
       9.121 [id=17]    INFO    jenkins.model.Jenkins#cleanUp: Jenkins stopped

1 test completed, 1 failed


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/me/jenkins-jobs-config/build/reports/tests/test/index.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

我尝试使用--stacktrace运行,但仍然收到相同的错误消息

如何查看实际错误是什么?在这种情况下,可能与丢失的文件夹插件有关

我可以通过将所有内容包装在这样的try catch中来强制执行此操作:

try {
        sldkjflskdfjlsd
} catch(Exception ex) {
        println ex.message 
        throw e
}

然后我将在运行spock测试时看到实际错误(由于showStandardStreams设置),但这似乎很愚蠢?我应该能够看到生成的异常,而不必捕获所有异常并将其转发到stdout或log。Im本质上是重新抛出了相同的异常,因此我可以查看运行spock测试时的实际问题。

编辑:由于某种原因,我什至不能使用错误级别适当的记录器,因为它会将所有日志输出到STANDARD_ERROR

尝试登录到信息

Logger logger = Logger.getLogger("")
logger.info 'looooogggggggggeeeeeerrrrrrr'

运行测试时查看

JobScriptsSpec > test script myscript.groovy STANDARD_ERROR
       9.228 [id=17]    INFO    java_util_logging_Logger$info$0#call: looooogggggggggeeeeeerrrrrrr

其他日志级别(logger.debug,logger.warn,logger.error)仅因以下错误而失败:

Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException at JobScriptsSpec.groovy:25

0 个答案:

没有答案