Run tests in CircleCI using the local CLI

The docs say that the local CLI is injected in the containers. It is the case, but trying to run circleci build in a container fails with this error:

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.


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 :smile_cat:

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.

You might be thinking of this thread: Circleci build (local machine) fails when using setup_remote_docker

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:

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

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

Yes exactly :slight_smile:

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?

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

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):

version: 2

      - image: circleci/node:8.11.4

      - 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

  version: 2
      - generator

Interesting project! :smiley_cat:

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 (
  • 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.

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

1 Like

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