Search code examples
yamlworkflowpipelinegithub-actions

How to execute command Post run in github actions?


Is there a way to execute a command post-run, no matter if the previous status was a success or failed something similar to post and always syntax in jenkinsfile

I have tried continue-on-error: true but this will make failed step as passed


Solution

  • You could use Job Status Check Functions with dependencies between jobs.

    For example:

    jobs:
      job1:
        continue-on-error: true
        # Do your stuff here
      job2:
        if: ${{ always() }}
        # Execute your post run command here
    

    I've created a sample workflow to show something similar working here using continue-on-error with this condition.

    You'll see in that example that even with an error on job2, job3 is still executed afterwards. This workflow run returns something like this (without the workflow failing and always executing the post run commands on job 3):

    Example