# Conditionally run commands

**URL:** <https://discuss.circleci.com/t/conditionally-run-commands/22293>\
**Category:** Build Environment\
**Created:** [May 10, 2018, 8:25pm UTC](https://discuss.circleci.com/t/conditionally-run-commands/22293 "2018-05-10T20:25:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![claytron5000](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/claytron5000/32/18403_2.png) [@claytron5000](https://discuss.circleci.com/u/claytron5000)\
**Post date:** [May 10, 2018, 8:25pm UTC](https://discuss.circleci.com/t/conditionally-run-commands/22293/1 "2018-05-10T20:25:26Z")

</div>

I would like to conditionally exit a job. Basically, I’m curling some info from the PR, and, depending on the data from that request, writing to a file, or not. I would like to exit the job depending on whether the file exists or not.

I tried:

```auto
steps:
      - attach_workspace:
          at: ~/ deploy_info
      - run: if [! -f ~/deploy_info/test_tags.txt] ; then exit 0 ; fi

```

But that just exits that command and continues with the job

---

<div class="post-metadata">

**Author:** ![levlaz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/levlaz/32/36978_2.png) [@levlaz](https://discuss.circleci.com/u/levlaz)\
**Post date:** [May 14, 2018, 2:42am UTC](https://discuss.circleci.com/t/conditionally-run-commands/22293/2 "2018-05-14T02:42:00Z")

</div>

> [@claytron5000](#):
>
> But that just exits that command and continues with the job

There is no way to do this right now, outside of wrapping the entire job in this type of conditional statement.

---

<div class="post-metadata">

**Author:** ![claytron5000](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/claytron5000/32/18403_2.png) [@claytron5000](https://discuss.circleci.com/u/claytron5000)\
**Post date:** [May 15, 2018, 8:55pm UTC](https://discuss.circleci.com/t/conditionally-run-commands/22293/3 "2018-05-15T20:55:06Z")

</div>

I’m doing the reverse, i’m triggering a job based on the existing file using a curl against the API: [https://circleci.com/docs/api/v1-reference/#new-build-branch](https://circleci.com/docs/api/v1-reference/#new-build-branch)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [August 13, 2018, 8:55pm UTC](https://discuss.circleci.com/t/conditionally-run-commands/22293/4 "2018-08-13T20:55:09Z")

</div>

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