Restoring cache fails with "Permission Denied"

If you are utilizing Workflows and either saving and restoring cache or persisting your Workspaces, keep in mind the users and directories involved. If you are using CircleCI convenience images, each Docker container runs under the same user with the same base permissions. If you save your cache in a job that uses one image, and it is restored in another, make sure they have compatible permissions.

 

If you receive the error "Permission denied" when restoring your cache, check where it had been saved in the previous job. A common instance of this is when using an image as the root user and saving cache, then attempting to restore that cache in a later job with a user who does not have root access.

The same error will cause files in a persisted workspace to be missing as well if the permissions are not set correctly.

Untitled.png

 

You can see here in this `Restoring Cache` step, the cache was originally saved to `/root/tmp` as the original image was running as root and had it's working directory set to `~/tmp`. In this part of the Workflow, running under the CircleCI user, we do not have access to the `/root` folder.

 

If possible, use the same image across multiple jobs. If this is not possible, try setting your working directory to a common location between the two images (`/tmp` may work for some). You may need to change or set file permissions before saving your cache.

Example: Use `chmod -R 777 ./workingDirectory` to give full read/write access to these files.

 

The best option is to use a common image among your jobs. If the convenience images we provide are missing something essential to your project, consider customizing one of our images.

 

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.