Rundeck - Getting exit code from a previous job step

297 views
Skip to first unread message

Ritesh Shukla

unread,
Oct 31, 2023, 1:39:40 PM10/31/23
to rundeck-discuss
I am trying to get the exit code from a previous job step, as outlined in the help documentation but it doesn't seem to work.

In Step 3, i am doing the following to get the exit code of step 2 : echo ${2.exit.exitCode}. 

Am i doing it correctly or this is not the right way?

rac...@rundeck.com

unread,
Oct 31, 2023, 2:33:22 PM10/31/23
to rundeck-discuss

Hi,

The doc site is wrong, please use echo ${2.exec.exitCode}. (Note that the doc refers to 2.exit.exitCode).

I’ll send a PR to fix that on the doc site.

Thanks!

Ritesh Shukla

unread,
Nov 1, 2023, 4:02:33 PM11/1/23
to rundeck-discuss
Thank you !

Ritesh Shukla

unread,
Nov 3, 2023, 3:55:14 PM11/3/23
to rundeck-discuss
Hi - I tried as per the suggestion above but am still not getting the expected output:

bin/sh: ${1.exec.exitCode}.: bad substitution

rac...@rundeck.com

unread,
Nov 3, 2023, 4:42:01 PM11/3/23
to rundeck-discuss

Hi,

If you’re using a command step, use the ${1.exec.exitCode} way.

If you’re using a script step (“inline script”): @1.exec.exitCode@ way.

Greetings.

Ritesh Shukla

unread,
Nov 3, 2023, 4:46:57 PM11/3/23
to rundeck-discuss
Hello - Thank you for the response but that is what i am trying to do. Following is a command step:

echo "The exit code of the previous step is ${1.exec.exitCode}".

But the above is throwing "bad substitution". 

Is it possible to try at your end as well once to rule out any anomaly with my environment?

TIA

Regards,
Ritesh

rac...@rundeck.com

unread,
Nov 3, 2023, 5:09:27 PM11/3/23
to rundeck-discuss

Hi!

Let me share a job definition example:

- defaultTab: nodes description: '' executionEnabled: true id: 52dac3c6-6ddf-42cc-a55b-6c636a917f59 loglevel: INFO name: HelloWorld nodeFilterEditable: false plugins: ExecutionLifecycle: null scheduleEnabled: true sequence: commands: - script: echo "hi" - exec: 'echo "first step exit code: ${1:exec.exitCode}"' - script: 'echo "first step exit code: @1:exec.exitCode@"' keepgoing: false strategy: node-first uuid: 52dac3c6-6ddf-42cc-a55b-6c636a917f59

Check the result here.

Ritesh Shukla

unread,
Nov 3, 2023, 7:10:38 PM11/3/23
to rundeck-discuss
Thank you so very much as i figured out what the issue was.

I was trying ${1.exec..}, whereas its ${1:exec} (it has a colon).

Much appreciated again.

Reply all
Reply to author
Forward
0 new messages