是否可以从 groovy 声明性管道中抛出的异常中抑制堆栈跟踪?
Is it possible to suppress the stack trace from a thrown Exception in groovy declarative pipelines?
我有一个带有输入步骤的声明性管道,可能会输入错误的输入。我已将阶段包装在重试块中,如果发现输入无效则抛出异常。
if (isValid == 1) {
println("Erroring out due to invalid change ticket")
throw new Exception("Please rerun the job and enter a valid change ticket")
} else {
println("CHG ticket is valid")
如果抛出此异常,则重新启动该阶段。
管道控制台吐出这个:
ERROR: Execution failed
java.lang.Exception: Please rerun the job and enter a valid change ticket
at WorkflowScript.run(WorkflowScript:197)
at ___cps.transform___(Native Method)
at sun.reflect.GeneratedConstructorAccessor1164.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at org.kohsuke.groovy.sandbox.impl.Checker.call(Checker.java:208)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onNewInstance(GroovyInterceptor.java:42)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onNewInstance(SandboxInterceptor.java:172)
at org.kohsuke.groovy.sandbox.impl.Checker.call(Checker.java:205)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedConstructor(Checker.java:210)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.constructorCall(SandboxInvoker.java:21)
Retrying
[Pipeline] {
[Pipeline] timeout
Timeout set to expire in 1 day 0 hr
[Pipeline] {
[Pipeline] input
Input requested
但我只关心我通过异常传递的消息。
有没有办法在 Jenkins 控制台中抑制此异常的堆栈跟踪?
使用 error
步骤 (Error Step)
error: Error signal
Signals an error. Useful if you want to conditionally abort some part of your program. You can also just throw new Exception(), but this step will avoid printing a stack trace.
if (isValid == 1) {
println("Erroring out due to invalid change ticket")
error("Please rerun the job and enter a valid change ticket")
} else {
println("CHG ticket is valid")
}
我有一个带有输入步骤的声明性管道,可能会输入错误的输入。我已将阶段包装在重试块中,如果发现输入无效则抛出异常。
if (isValid == 1) {
println("Erroring out due to invalid change ticket")
throw new Exception("Please rerun the job and enter a valid change ticket")
} else {
println("CHG ticket is valid")
如果抛出此异常,则重新启动该阶段。
管道控制台吐出这个:
ERROR: Execution failed
java.lang.Exception: Please rerun the job and enter a valid change ticket
at WorkflowScript.run(WorkflowScript:197)
at ___cps.transform___(Native Method)
at sun.reflect.GeneratedConstructorAccessor1164.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at org.kohsuke.groovy.sandbox.impl.Checker.call(Checker.java:208)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onNewInstance(GroovyInterceptor.java:42)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onNewInstance(SandboxInterceptor.java:172)
at org.kohsuke.groovy.sandbox.impl.Checker.call(Checker.java:205)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedConstructor(Checker.java:210)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.constructorCall(SandboxInvoker.java:21)
Retrying
[Pipeline] {
[Pipeline] timeout
Timeout set to expire in 1 day 0 hr
[Pipeline] {
[Pipeline] input
Input requested
但我只关心我通过异常传递的消息。
有没有办法在 Jenkins 控制台中抑制此异常的堆栈跟踪?
使用 error
步骤 (Error Step)
error: Error signal Signals an error. Useful if you want to conditionally abort some part of your program. You can also just throw new Exception(), but this step will avoid printing a stack trace.
if (isValid == 1) {
println("Erroring out due to invalid change ticket")
error("Please rerun the job and enter a valid change ticket")
} else {
println("CHG ticket is valid")
}