jenkins groovy file steps management : make steps continue on previous errors
hello I uses a jenkins groovy file to manage steps of my pipeline.
structure is just like :
> ```
>
> 2 pipeline 3 {
> 4 agent none
> 5
> 6 options {
> 7 timeout(time: 240, unit: 'MINUTES')
> 8 }
> 9
> 10 stages {
> 11 stage ("clean xxxxxxx") {
> 12 agent {
> 13 node {
> 14 label "xxxxxxx"
> 15 customWorkspace "F:\\xxxxxxx"
> 16 }
> 17 }
> 18 steps
> 19 {
> 20 script
> 21 {
> 22 bat """
> 23 f:
> 24 cd \\
> 25 python
> xxxxxxx/scripts/pipeline/removeOldJenkinsBuildDir.py --nbdays 30
> --delete yes 26 python
> xxxxxxx/scripts/pipeline/cleanDotConan.py f: --delete
> 27 Powershell("Get-wmiObject -Class
> win32_logicaldisk")
> 28 """
> 29 }
> 30 }
> 31 }
>
> ```
and so on for each nodes of my list.
my issue
if one step fails all of the rest starts and ignore message :
Stage "clean XXXXXXXX" skipped due to earlier failure(s)
.
so steps are skipped but I really want them to run.
my goal
set something in here maybe in steps or higher level, to avoid that skip and force all steps to be run. what can I do for that ? change options sets ? add options to each step ?
(in fact I found many exemples ; but was unable to use them or crashed :) )
Solution 1:
This is addressed in the official documentation, which provides two suggestions: the Pipeline step catchError { }
and the native Groovy try
-catch
-finally
syntax for handling exceptions.
Since it sounds like you may want your code to repeat on many different nodes, another option may be to put your nodes into parallel
blocks. A failure in one parallel branch will not halt execution in any of the other parallel branches.