# How to: Abort workflow if previous build isn't "Green"?

**URL:** <https://discuss.bitrise.io/t/how-to-abort-workflow-if-previous-build-isnt-green/10821>\
**Category:** Question & Answer\
**Created:** [November 2, 2019, 7:39am UTC](https://discuss.bitrise.io/t/how-to-abort-workflow-if-previous-build-isnt-green/10821 "2019-11-02T07:39:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![YellowstoneApps](https://avatars.discourse-cdn.com/v4/letter/y/e5b9ba/32.png) [@YellowstoneApps](https://discuss.bitrise.io/u/YellowstoneApps)\
**Post date:** [November 2, 2019, 7:39am UTC](https://discuss.bitrise.io/t/how-to-abort-workflow-if-previous-build-isnt-green/10821/1 "2019-11-02T07:39:26Z")

</div>

I would like my `build_nightlies ` scheduled job to only execute if the current branch is ‘green’. Is it possible to detect the build status of the branch and then start/stop a workflow based on that resut?

A bit more context:

I’ve got a `run_tests` job that runs all day long on every code push. I’ve also scheduled a `build_nightlies` job to run in the middle of the night, but I only want it to build things if the last `run_tests` job ran successfully.

I know I could set up a workflow to execute my `run_tests` and then `build_nightlies` jobs, but it’s unnecessary to execute `run_tests` again since that would just be redundant of the previous build.

---

<div class="post-metadata">

**Author:** ![koral](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/koral/32/357_2.png) [@koral](https://discuss.bitrise.io/u/koral)\
**Post date:** [November 2, 2019, 11:32am UTC](https://discuss.bitrise.io/t/how-to-abort-workflow-if-previous-build-isnt-green/10821/2 "2019-11-02T11:32:29Z")

</div>

You can use Bitrise API to query status of the latest `run_tests` build status at the beginning of the `build_nightlies` - eg. fail it if conditions are not met. [https://api-docs.bitrise.io/](https://api-docs.bitrise.io/)

---

<div class="post-metadata">

**Author:** ![YellowstoneApps](https://avatars.discourse-cdn.com/v4/letter/y/e5b9ba/32.png) [@YellowstoneApps](https://discuss.bitrise.io/u/YellowstoneApps)\
**Post date:** [November 2, 2019, 12:02pm UTC](https://discuss.bitrise.io/t/how-to-abort-workflow-if-previous-build-isnt-green/10821/3 "2019-11-02T12:02:49Z")

</div>

Ah, didn’t know about that. Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/d/d901cf2aad020f2dd11918afc89ec2089bb87b35.png) [@system](https://discuss.bitrise.io/u/system)\
**Post date:** [August 19, 2022, 5:26am UTC](https://discuss.bitrise.io/t/how-to-abort-workflow-if-previous-build-isnt-green/10821/4 "2022-08-19T05:26:00Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
