Skip to main content
deleted 409 characters in body
Source Link
jayhendren
  • 3k
  • 8
  • 15

First - try/catch only works in Scripted Pipeline, not Declarative, so make sure you are running Scripted Pipelines or putting your try/catch code into a script block, otherwise it won't work as you expect. If you are using Declarative, use catchError instead.

Second, Scripted Pipeline. usesuse regular Groovy, so you would use the normal Groovy approach for this:

try { 
   checkout() 
} catch(hudson.plugins.git.GitException e) { 
   // handle a GitException 
} catch(hudson.AbortException e) { 
   // handle an AbortException 
} finally {
   // cleanup
}

First - try/catch only works in Scripted Pipeline, not Declarative, so make sure you are running Scripted Pipelines or putting your try/catch code into a script block, otherwise it won't work as you expect. If you are using Declarative, use catchError instead.

Second, Scripted Pipeline. uses regular Groovy, so you would use the normal Groovy approach for this:

try { 
   checkout() 
} catch(hudson.plugins.git.GitException e) { 
   // handle a GitException 
} catch(hudson.AbortException e) { 
   // handle an AbortException 
} finally {
   // cleanup
}

Pipelines use regular Groovy, so you would use the normal Groovy approach for this:

try { 
   checkout() 
} catch(hudson.plugins.git.GitException e) { 
   // handle a GitException 
} catch(hudson.AbortException e) { 
   // handle an AbortException 
} finally {
   // cleanup
}
Source Link
jayhendren
  • 3k
  • 8
  • 15

First - try/catch only works in Scripted Pipeline, not Declarative, so make sure you are running Scripted Pipelines or putting your try/catch code into a script block, otherwise it won't work as you expect. If you are using Declarative, use catchError instead.

Second, Scripted Pipeline. uses regular Groovy, so you would use the normal Groovy approach for this:

try { 
   checkout() 
} catch(hudson.plugins.git.GitException e) { 
   // handle a GitException 
} catch(hudson.AbortException e) { 
   // handle an AbortException 
} finally {
   // cleanup
}