# Run tests in CircleCI using the local CLI

**URL:** <https://discuss.circleci.com/t/run-tests-in-circleci-using-the-local-cli/24986>\
**Category:** Running Tests\
**Created:** [September 9, 2018, 10:41am UTC](https://discuss.circleci.com/t/run-tests-in-circleci-using-the-local-cli/24986 "2018-09-09T10:41:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![williamdclt](https://avatars.discourse-cdn.com/v4/letter/w/e68b1a/32.png) [@williamdclt](https://discuss.circleci.com/u/williamdclt)\
**Post date:** [September 9, 2018, 10:41am UTC](https://discuss.circleci.com/t/run-tests-in-circleci-using-the-local-cli/24986/1 "2018-09-09T10:41:11Z")

</div>

The docs say that [the local CLI is injected in the containers](https://circleci.com/docs/2.0/parallelism-faster-jobs/#using-the-circleci-cli-to-split-tests). It is the case, but trying to run `circleci build` in a container fails with this error:

 ![image](https://global.discourse-cdn.com/circleci/original/3X/6/0/601164d7c5b2b82eafa41dafa7b4a00e6c7a48eb.png)

I tried adding a `setup_remote_docker` step before, but then I have this error: `Unexpected environment preparation error: error connecting build-agent to ephemeral network: error connecting build-agent container to ephemeral network: Error response from daemon: No such container: 24f3f0f1945b1e5183bdd0b04e41bd57227ec1bdbeed1b58b47672d249f96f41`

Am I missing something, is it even something that is supposed to be possible to do?  
For the context: I’m testing a project generator. I’m generating a project then checking that the _generated project_ tests are passing.

Thanks!

---

<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:** [September 9, 2018, 1:49pm UTC](https://discuss.circleci.com/t/run-tests-in-circleci-using-the-local-cli/24986/2 "2018-09-09T13:49:38Z")

</div>

I think someone asked about this recently, but I can’t find it. I _think_ the easy solution is to run the command with `sudo`, but I recall when I had that conversation here, the reporter did not trust CircleCI enough for that 😸

I wonder if adding `docker` to your user groups would do it? That is Docker’s way of allowing non-root users to control Docker.

---

<div class="post-metadata">

**Author:** ![williamdclt](https://avatars.discourse-cdn.com/v4/letter/w/e68b1a/32.png) [@williamdclt](https://discuss.circleci.com/u/williamdclt)\
**Post date:** [September 9, 2018, 2:25pm UTC](https://discuss.circleci.com/t/run-tests-in-circleci-using-the-local-cli/24986/3 "2018-09-09T14:25:02Z")

</div>

You might be thinking of this thread: [Circleci build (local machine) fails when using setup\_remote\_docker](https://discuss.circleci.com/t/circleci-build-local-machine-fails-when-using-setup-remote-docker/15487/2)

My situation is different: I don’t care too much about running `circleci build` on my machine, I want it to run _inside the container_ (circlecinception).

More clearly, I have this step in my generator .circleci/config:

```auto
      - run:
          name: Check generated tests
          working_directory: ./myTestProject
          command: circleci build --job backend

```

---

<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:** [September 9, 2018, 4:29pm UTC](https://discuss.circleci.com/t/run-tests-in-circleci-using-the-local-cli/24986/4 "2018-09-09T16:29:57Z")

</div>

Righto; you’re running the CircleCI cli command on a remote CircleCI build machine?

---

<div class="post-metadata">

**Author:** ![williamdclt](https://avatars.discourse-cdn.com/v4/letter/w/e68b1a/32.png) [@williamdclt](https://discuss.circleci.com/u/williamdclt)\
**Post date:** [September 9, 2018, 4:42pm UTC](https://discuss.circleci.com/t/run-tests-in-circleci-using-the-local-cli/24986/5 "2018-09-09T16:42:14Z")

</div>

Yes exactly 🙂

---

<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:** [September 9, 2018, 4:52pm UTC](https://discuss.circleci.com/t/run-tests-in-circleci-using-the-local-cli/24986/6 "2018-09-09T16:52:26Z")

</div>

OK. It _may_ help to give some background as to why you want to do that - what do you want to achieve? There is likely to be a better way to do what you are doing.

However, I do have experience of Docker in CircleCI (known as _Docker in Docker_). You need to pull your own images, and you need to have Docker installed and running. Would you post the whole of your `config.yml`, in a formatted block, so I and other readers can take a look?

---

<div class="post-metadata">

**Author:** ![williamdclt](https://avatars.discourse-cdn.com/v4/letter/w/e68b1a/32.png) [@williamdclt](https://discuss.circleci.com/u/williamdclt)\
**Post date:** [September 9, 2018, 5:12pm UTC](https://discuss.circleci.com/t/run-tests-in-circleci-using-the-local-cli/24986/7 "2018-09-09T17:12:35Z")

</div>

They might be a better way, but I don’t see it 🙂

So, my project is called ProjectGenerator and… it generates projects. Basically you clone it, you run `make django react` and poof, you get all the boilerplate for a Django/React project.

ProjectGenerator has a .circleci/config.yml, and generated projects have one too.

What I would like to do in the CI of ProjectGenerator is:

1. generate a project
2. check that the tests _of the generated project_ are passing.

For that, my ProjectGenerator/.circleci/config.yml looks like that (shortened, the actual one is quite long):

```auto
version: 2

jobs:
  generator:
    docker:
      - image: circleci/node:8.11.4

    steps:
      - checkout

      - run:
          name: Start a new Django/React project
          command: make target=./myTestProject django react 

      - run:
          name: Run the generated project tests
          working_directory: myTestProject
          command: |
            circleci build --job backend
            circleci build --job frontend

workflows:
  version: 2
  stack:
    jobs:
      - generator

```

---

<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:** [September 9, 2018, 5:18pm UTC](https://discuss.circleci.com/t/run-tests-in-circleci-using-the-local-cli/24986/8 "2018-09-09T17:18:56Z")

</div>

Interesting project! 😺

I would do it a different way though. Here is what I would investigate:

- Publish the project to a Git repo (public or private)
- Get your CircleCI account to follow it using the API ([https://circleci.com/docs/api/v1-reference/](https://circleci.com/docs/api/v1-reference/))
- Trigger a new build using the API
- Periodically get a summary of the latest builds to see if the build finished, using the API
- Remotely delete the Git repo

(Sadly there isn’t an “unfollow” endpoint, so you may have a long list of dead projects in your CircleCI UI, but that’s not much of a bother).

Would this be worth investigating?

Of course, this will test your whole CircleCI config. However, if you just want to run some Django tests, you could just pull these into a Docker container on the server your ProjectGenerator runs on, and run them there from a queue.

---

<div class="post-metadata">

**Author:** ![williamdclt](https://avatars.discourse-cdn.com/v4/letter/w/e68b1a/32.png) [@williamdclt](https://discuss.circleci.com/u/williamdclt)\
**Post date:** [September 9, 2018, 5:32pm UTC](https://discuss.circleci.com/t/run-tests-in-circleci-using-the-local-cli/24986/9 "2018-09-09T17:32:51Z")

</div>

That would probably do it, but is probably more effort than I am willing to put in! If I can’t `circleci build`, I’ll probably just `circleci config validate` and copy the steps from the generated project .circleci/config to ProjectGenerator/.circleci/config

---

<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:** [December 8, 2018, 5:32pm UTC](https://discuss.circleci.com/t/run-tests-in-circleci-using-the-local-cli/24986/10 "2018-12-08T17:32:51Z")

</div>

Closed on December 8, 2018, 5:32pm UTC

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