如果管道脚本部分在重试块中重新执行,我怎么看?

时间:2017-09-18 10:45:36

标签: jenkins jenkins-pipeline

在管道脚本中,我在某些情况下使用retry块。

retry(1){
  timeout(...){
    try{
      sh 'do something'
    }catch(...){...}
  }
}

我无法在控制台输出中找到任何信息,是否“重试”了一个块。有没有机会看看我的retry(1){...}块是否有效?

谢谢!

1 个答案:

答案 0 :(得分:1)

重试(1)表示该块仅执行一次(因此不进行任何重试)

我试过了:

node{
    retry(2){
        float a = 0/0;
    }
}

正如您所看到的,它显示在de console输出中:

Started by user Carlos Lucas
Running as Carlos Lucas
[Pipeline] node
Running on master in /var/lib/jenkins/workspace/zProves/retry
[Pipeline] {
[Pipeline] retry
[Pipeline] {
[Pipeline] }
ERROR: Execution failed
java.lang.ArithmeticException: Division undefined
    at java.math.BigDecimal.divide(BigDecimal.java:1741)
    at org.codehaus.groovy.runtime.typehandling.BigDecimalMath.divideImpl(BigDecimalMath.java:68)
    at org.codehaus.groovy.runtime.typehandling.IntegerMath.divideImpl(IntegerMath.java:49)
    at org.codehaus.groovy.runtime.typehandling.NumberMath.divide(NumberMath.java:68)
    at org.codehaus.groovy.runtime.dgmimpl.NumberNumberDiv.invoke(NumberNumberDiv.java:32)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
[...]
Retrying
[Pipeline] {
[Pipeline] }
[Pipeline] // retry
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.ArithmeticException: Division undefined
    at java.math.BigDecimal.divide(BigDecimal.java:1741)
    at org.codehaus.groovy.runtime.typehandling.BigDecimalMath.divideImpl(BigDecimalMath.java:68)
    at org.codehaus.groovy.runtime.typehandling.IntegerMath.divideImpl(IntegerMath.java:49)
    at org.codehaus.groovy.runtime.typehandling.NumberMath.divide(NumberMath.java:68)
    at org.codehaus.groovy.runtime.dgmimpl.NumberNumberDiv.invoke(NumberNumberDiv.java:32)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
[...]
Finished: FAILURE