Search code examples
github-actions

How to pass success() or failure() to a github action from a workflow


So I have a github workflow that calls a composite action at the end, regardless of success or failure. I want to pass whether or not the workflow has succeeded to the action to use within it. I have tried passing success() as bellow, I have also tried writing success into a variable in a step and then calling that variable. Is success() only able to be called inside a if:, and if so is there any similar way to get the workflows status.

The code I have tried looks like this:

...previous steps

- name: The step to call the action
  if: always()
  uses: ./path/to/action
  with:
    some-token: ${{ inputs.some-token }}
    some-value: ${{ inputs.some-value }}
    workflow-status: ${{ success() }}

Solution

  • You could use the outcome of the previous step.

    when a step fails. Set to true to allow a job to pass when this step fails

    Check the outcome of the step in order to understand if was failed or not like:

    steps.<id>.outcome != 'success'
    

    See outcome doc here and continue-on-error