# How to run a single build at a time

**URL:** <https://discuss.circleci.com/t/how-to-run-a-single-build-at-a-time/24450>\
**Category:** Build Environment\
**Created:** [August 17, 2018, 2:04pm UTC](https://discuss.circleci.com/t/how-to-run-a-single-build-at-a-time/24450 "2018-08-17T14:04:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jggc](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jggc/32/19310_2.png) [@jggc](https://discuss.circleci.com/u/jggc)\
**Post date:** [August 17, 2018, 2:04pm UTC](https://discuss.circleci.com/t/how-to-run-a-single-build-at-a-time/24450/1 "2018-08-17T14:04:36Z")

</div>

We are a small team (2-3 devs) and we want only a single build running at a time for our github repo.

The reason is that we are doing continuous delivery + acceptance testing in our staging and production environments, but when multiple builds run at the same time the deployment of a build can break acceptance tests of another, especially on staging where we deploy automatically feature branches.

Our account is part of a larger organization which I don’t control.

Ideally I would be able to disable parallelization only for a few steps of the build (deployment and acceptance testing) but that does not seem to be possible to configure for an entire repository.

---

<div class="post-metadata">

**Author:** ![grahamw](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/grahamw/32/18777_2.png) [@grahamw](https://discuss.circleci.com/u/grahamw)\
**Post date:** [August 18, 2018, 12:31am UTC](https://discuss.circleci.com/t/how-to-run-a-single-build-at-a-time/24450/2 "2018-08-18T00:31:51Z")

</div>

Hi @jggc, just to clarify your requirement. It sounds like your saying that for this one specific repo, you’d like to ensure that if there are 2 pushes to you repo, let says say 15 seconds apart that the 2nd build from the second push should queue entirely behind the first. Is that correct?

Also, do you have workflows setup on that repo? The current default behaviour that I’ve observed is that if you have a workflow with 2 steps and the first job from the first build is still running when a subsequent push occurs, then the 2nd job from the first push will get queued behind the 1st job of the 2nd queue. I hope that makes sense, it seems to. 🙂 So, the results is that the jobs from both workflows end up interleaved.

Probably need clarification on what your setup is as well. Are you able to supply your config.yml either here or in a gist?

---

<div class="post-metadata">

**Author:** ![jggc](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jggc/32/19310_2.png) [@jggc](https://discuss.circleci.com/u/jggc)\
**Post date:** [August 18, 2018, 5:12pm UTC](https://discuss.circleci.com/t/how-to-run-a-single-build-at-a-time/24450/3 "2018-08-18T17:12:15Z")

</div>

Yep you got it right I want builds to get queued instead of ran at the same time.

I am trying with workflow though and it runs in parallel. I pushed two dummy commits about 30 seconds apart and both workflows started immediately and all jobs of the workflow were run without any queuing.

So your solution does not work… Plus using workflow makes the build much longer as circle rebuilds the entire context between each step.

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [August 18, 2018, 6:51pm UTC](https://discuss.circleci.com/t/how-to-run-a-single-build-at-a-time/24450/4 "2018-08-18T18:51:18Z")

</div>

> [@jggc](#):
>
> Plus using workflow makes the build much longer as circle rebuilds the entire context between each step.

This is a separate issue, but you might be able to use workspaces to fix this. As @grahamw suggests, readers could do with seeing your config to be able to offer more specific help.

---

<div class="post-metadata">

**Author:** ![jggc](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jggc/32/19310_2.png) [@jggc](https://discuss.circleci.com/u/jggc)\
**Post date:** [August 19, 2018, 12:37pm UTC](https://discuss.circleci.com/t/how-to-run-a-single-build-at-a-time/24450/5 "2018-08-19T12:37:39Z")

</div>

> [@halfer](#):
>
> but you might be able to use workspaces to fix this.

Thanks I’ll try that.

Aaand here is my (anonymized) circle config.xml.

```
version: 2
jobs:
  unit_tests:
    docker:
      - image: someimage:latest
        auth:
          username: somedockeruser
          password: $DOCKERHUB_PASSWORD
    working_directory: ~/repo
    steps:
      - checkout
      # Download and cache dependencies
      - restore_cache:
          keys:
          - main-dependencies-v3-{{ checksum "package-lock.json" }}
          - main-dependencies-v3-
      - restore_cache:
          keys:
          - cloud-functions-dependencies-v3-{{ checksum "functions/package-lock.json" }}
          - cloud-functions-dependencies-v3-
      - run: ./.circleci/dependencies.sh
      - save_cache:
          paths:
            - node_modules
          key: main-dependencies-v3-{{ checksum "package-lock.json" }}
      - save_cache:
          paths:
            - functions/node_modules
          key: cloud-functions-dependencies-v3-{{ checksum "functions/package-lock.json" }}
      - run: ./.circleci/server-tests-unit.sh
      - run: ./.circleci/tests-unit.sh
  accept_test_staging:
    docker:
      - image: someimage:latest
        auth:
          username: someuser
          password: $DOCKERHUB_PASSWORD
    working_directory: ~/repo
    steps:
      - checkout
      - restore_cache:
          keys:
          - main-dependencies-v3-{{ checksum "package-lock.json" }}
          - main-dependencies-v3-
      - restore_cache:
          keys:
          - cloud-functions-dependencies-v3-{{ checksum "functions/package-lock.json" }}
          - cloud-functions-dependencies-v3-
      - run: ./.circleci/build-staging.sh
      - run: ./.circleci/deploy-staging.sh
      - run: ./.circleci/wait-staging.sh
      - run: ./.circleci/tests-accept.sh
      - store_artifacts:
          path: screenshots
  deploy_prod:
    docker:
      - image: someimage:latest
        auth:
          username: someuser
          password: $DOCKERHUB_PASSWORD
    working_directory: ~/repo
    steps:
      - checkout
      - restore_cache:
          keys:
          - main-dependencies-v3-{{ checksum "package-lock.json" }}
          - main-dependencies-v3-
      - restore_cache:
          keys:
          - cloud-functions-dependencies-v3-{{ checksum "functions/package-lock.json" }}
          - cloud-functions-dependencies-v3-
      - run: ./.circleci/build-prod.sh
      - run: ./.circleci/deploy-prod.sh
      - run: ./.circleci/wait-prod.sh
      - run: ./.circleci/deploy-mobile-code-push.sh
workflows:
  version: 2
  test_and_deploy:
    jobs:
      - unit_tests
      - accept_test_staging:
          requires:
            - unit_tests
      - deploy_prod:
          requires:
            - accept_test_staging
          filters:
            branches:
              only: 'master'

```

Thanks for the help so far, I hope we’ll figure it out!

---

<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:** [November 17, 2018, 12:37pm UTC](https://discuss.circleci.com/t/how-to-run-a-single-build-at-a-time/24450/6 "2018-11-17T12:37:45Z")

</div>

Closed on November 17, 2018, 12:37pm UTC

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