How to gracefully stop job execution when one step

2019-07-24 06:31发布

问题:

So I defined a Rundeck job which normally executes three steps:

  1. run script to check remote directory for .csv files and rsync them
  2. manipulate csv files
  3. rsync the csvs back to remote dir

now I set up the script run on step 1 to finish with exit code 1 when there are no csv files in my remote directory, upon which it does not execute steps 2 and 3 - which is great! But the whole job is marked as having failed even though it just didn't need to execute the other steps.

Is it possible to conditionally execute steps 2 and 3 of my job such that if step 1 fails it is still marked as 'succeeded'?

回答1:

It is possible with Rundeck Error Handlers.

You will need to use the job context variable ${result.resultCode} in your error handler code in order to get a return code.

As you don't want the job marked as failed after the Error Handler was successfully executed, you need to tick Keep going on success from WebUI or add keepgoingOnSuccess="true" to you job definition code.

But after the error handler was successfully executed, the job will continue step 2 and step 3, where you may need to inject your step 2 code for it.



标签: rundeck