Skip to content

How can I capture exit code of run command and reuse in another job ? #46992

Discussion options

You must be logged in to vote

By default the shell for run steps is configured to exit as soon as a command fails (that's the -e in the shell definition). So for any exit code != 0 the echo to set the output will never run.

You should be able to override that by setting the shell yourself, or (more obvious) disable the "exit on failure":

      - name: Plan
        id: plan
        run: |
          set +e
          <some command here executed>
          echo "exitcode=$?" >> $GITHUB_OUTPUT

Mind that this way the exit code of the last command will become the exit code of the step, so it won't be marked as failed. If you don't want that, you can carry the exit code over:

      - name: Plan
        id: plan
        run: |

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@nicfv
Comment options

@airtower-luna
Comment options

@piranna
Comment options

@nicfv
Comment options

@piranna
Comment options

Answer selected by Constantin07
Comment options

You must be logged in to vote
1 reply
@sohale
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment