Mkdir doesn't work correctly


#1

I have tons of issues with mkdir all the time.

I have this line in my config.yml:

  - run:
      name: Save Docker image layer cache
      command: |
        mkdir -p caches
        docker save -o /caches/app.tar app

It worked fine for a long time but suddenly I am seeing this:

failed to save image: unable to validate output path: directory "/caches" does not exist
Exited with code 1

Why isn’t mkdir -p caches working?

I had the same problem with mkdir -p test-results/coverage test-results/nose
The directories wouldn’t be found with mkdir and I ended up having to just put a .gitkeep in those folders.

But /caches/ did work until recently. Overall I really don’t get why mkdir doesn’t seem to actually create directories.


#2

I suspect your command is being run relative to the default build folder, and this is not the FS root (/). Try swapping this to mkdir -p /caches.


#3

Also if you are going to try to make a folder under / (root) then you might run into a permissions issue so you should do it as sudo.


#4

I’ll try that. But it was working fine before for a while the way it is now. Not sure why suddenly it isn’t. I have the same problem with the test results directories. Although they had the issue from the start.

Makes no sense to me why it wouldn’t work. Hopefully your suggestion fixes it even if it doesn’t explain why it worked fine until now


#5

Was working_directory set to / at any point, by any chance? It could also be a change to the image – if you go back to the last time it succeeded, under “spin up containers” you should be able to view the sha256 digest of the image. You can then pin this by specifying (for example):

- image: circleci/ruby@sha256:afbbf67e01be90e59a9d838175f320b8187fa477aed98dadb53688d8d80dbff1

See whether this changes the behaviour, and that may help you to find out why this changed initially.