Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 4

Github Actions trigger workflow on Succes/Failure of other Workflow

Assuming I have a repository with and two github actions workflows. (1st workflow consists of about 15 actions, 2nd workflow consists of 5 actions)

The first one is triggered "on push" 

The second one should trigger after first one fails or succeds to do some side work (i.e. send notifications, create report etc). 

Especially interesting is the failure case.

I have tried to set  "on ="check_suite"" for the second workflow. But it does not get triggered.  (When I query explecitely the check-suites API, I see the updated information about runs, but I need a trigger on that)

 

I should be missing something basic concept here...

 

3 Replies
Community Manager
Message 2 of 4

Re: Github Actions trigger workflow on Succes/Failure of other Workflow

It sounds like you're confusing the concepts of "workflow" and "action". A workflow consists of multiple actions that can depend on one another or run independently. So if you want something to happen after something else, they should probably be two actions in the same workflow. Now, an action that depends on another action will not be executed if the depended upon action fails, but because actions are so open-ended I'm not sure what it is that you need to do on failure that couldn't be accomplised within the action.

 

Example requirements:

 

  1. Build the code
  2. If code fails to build, send an email to Dev
  3. If code successfully built, run tests
  4. Email test report to QA

 

For this, I would create one workflow consisting of two actions:

 

  1. Build the code, send email to Dev on failure
  2. Test code, email test report to QA

 

Would something like that work for your envisioned use case?

Highlighted
Copilot Lvl 2
Message 3 of 4

Re: Github Actions trigger workflow on Succes/Failure of other Workflow

My main build workflow consits of about 15 actions. Any of these actions can fail leading to the fail of whole workflow. Putting the same failure handling to every action is not always possible especially when using some 3d party public actions.  

 

Besides that, the failure handling itself is not a single step. It contains of 5 actions. 

For that reason I would like keep the Failure handling separeted and bundeled as its own workflow consisting of multiple actions.

 

I would like that the "failure workflow" gets triggered whenever "main build workflow" fails (due to failure of any of its actions)

Or even more broadly I would like to chain workflows. So that sencond one kicks of when the first is finished.

I hoped to use "check_suite event" as a trigger, but this did not work out for some reason :(

 

 

Copilot Lvl 2
Message 4 of 4

Re: Github Actions trigger workflow on Succes/Failure of other Workflow


@lee-dohm wrote:

It sounds like you're confusing the concepts of "workflow" and "action". A workflow consists of multiple actions that can depend on one another or run independently. So if you want something to happen after something else, they should probably be two actions in the same workflow. Now, an action that depends on another action will not be executed if the depended upon action fails, but because actions are so open-ended I'm not sure what it is that you need to do on failure that couldn't be accomplised within the action.

 

Example requirements:

 

  1. Build the code
  2. If code fails to build, send an email to Dev
  3. If code successfully built, run tests
  4. Email test report to QA

 

For this, I would create one workflow consisting of two actions:

 

  1. Build the code, send email to Dev on failure
  2. Test code, email test report to QA

 

Would something like that work for your envisioned use case?


 

There are cases that at the end of a workflow, no matter if it has completed successfully or if it has failed, we need to execute certain tasks. Or we might need to execute some tasks if any of the workflow steps have failed. The CI/CD tools I have used in the past all support this functionality. See https://jenkins.io/doc/book/pipeline/syntax/#post for an example in Jenkins.