Workspaces with parallel workflows

I was working on a parallel workflow for some React deployments to separate out the build and deploy phases like this:

[ build staging ] => [deploy staging] => [approval] => [deploy prod]
[ build prod ]

using workspaces to store the built app between the corresponding build and deploy steps. This works great in a case where there’s only a single job in the workflow.

I had slightly misunderstood the description of how concurrent workflows and workspaces interacted in:

So, I got the error: Concurrent upstream jobs persisted the same file(s), which now totally makes sense to me.

My question is: is there any way to get the behavior I want with workspaces (assuming the built directory is always the same on the source side, e.g., build/)? Is there a way to use a unique path with persist_to_workspace without actually renaming the directory, or would I need to do something like mv build build_prod and persist that? Can I use env vars in the path name if I go that route?

I am thinking that using artifacts instead would not really be the right use case for this purpose?


It is possible to write to the same workspace on multiple jobs as long as the files or directories are different. It is ok to write to different subdirectories with the same files as they will be treated as separate folders so you could use mv build build_prod and persist that.

If you are looking for a way to generate different names it is possible to use the built-in variables within CircleCI which include a number of different options outlined in the documentation below:

I hope this help but if you have any questions I will be happy to help.

Kind Regards
Owen Oliver