# Preventing users from rebuilding branches

**URL:** <https://discuss.circleci.com/t/preventing-users-from-rebuilding-branches/7245>\
**Category:** Deployments\
**Created:** [October 6, 2016, 1:58pm UTC](https://discuss.circleci.com/t/preventing-users-from-rebuilding-branches/7245 "2016-10-06T13:58:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonmorley](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/simonmorley/32/996_2.png) [@simonmorley](https://discuss.circleci.com/u/simonmorley)\
**Post date:** [October 6, 2016, 1:58pm UTC](https://discuss.circleci.com/t/preventing-users-from-rebuilding-branches/7245/1 "2016-10-06T13:58:03Z")

</div>

We have GitHub setup with master as a protected branch.

However, non-admins can trigger a rebuild / multiple rebuilds in Circle. On any branch.

In our case, that means, contributors are able to redeploy our application.

What is the best way to prevent this? We basically only need the project to deploy if account X did it.

The only way I can see, is to set the CIRCLE\_USERNAME var in the deploy script.

---

<div class="post-metadata">

**Author:** ![tom](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/tom/32/27680_2.png) [@tom](https://discuss.circleci.com/u/tom)\
**Post date:** [October 6, 2016, 4:14pm UTC](https://discuss.circleci.com/t/preventing-users-from-rebuilding-branches/7245/2 "2016-10-06T16:14:26Z")

</div>

The approach you suggest sounds like a good way to achieve this. You can check for approved values via that env var and some conditional logic in `circle.yml`.

You could also set it so that only the master branch deploys if that suits your workflow: [https://circleci.com/docs/configuration/#deployment](https://circleci.com/docs/configuration/#deployment)

---

<div class="post-metadata">

**Author:** ![simonmorley](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/simonmorley/32/996_2.png) [@simonmorley](https://discuss.circleci.com/u/simonmorley)\
**Post date:** [October 6, 2016, 4:35pm UTC](https://discuss.circleci.com/t/preventing-users-from-rebuilding-branches/7245/3 "2016-10-06T16:35:20Z")

</div>

That’s the point - only master builds do deploy.

But, they can be rebuilt again and again and again and again and again. By anyone.

---

<div class="post-metadata">

**Author:** ![fearphage](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/fearphage/32/13972_2.png) [@fearphage](https://discuss.circleci.com/u/fearphage)\
**Post date:** [October 14, 2016, 4:00am UTC](https://discuss.circleci.com/t/preventing-users-from-rebuilding-branches/7245/4 "2016-10-14T04:00:24Z")

</div>

I don’t have a guranteed solution, but I may have some possible workarounds. Have you tried messing with the `owner` in the deployment section? Another thing to look at is the `$CIRCLE_PREVIOUS_BUILD_NUM` environment variable. The first build shouldn’t have this filled in while all the rebuilds should. Also checking the `$CIRCLE_USERNAME` is a permitted user.

---

<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:** [June 18, 2018, 11:41am UTC](https://discuss.circleci.com/t/preventing-users-from-rebuilding-branches/7245/5 "2018-06-18T11:41:07Z")

</div>


