If the build hits the memory limit, CircleCI will save a file called memory-usage.txt into the Artifacts tab for that build. This is described in more detail in this doc. However, the memory usage will only be logged in the builds that finish with out-of-memory errors.
If you would like to monitor memory usage in your build pro-actively, you could add something like this to your circle.yml file:
- FILE=$CIRCLE_ARTIFACTS/memory-usage-actual.txt; while true; do ps -u ubuntu eo pid,%cpu,%mem,args,uname --sort=-%mem >> $FILE; echo "----------" >> $FILE; sleep 1; done: # note the colon here
background: true
This command will run in the background and will generate the memory usage stats every second till the build finishes, one per line.
artifacts should be as stated in the error message an array of files and directories. The paths listed there will end up in the artifacts tab in your build. (See Specifying custom artifacts directories and files)
However if you put any file within the directory that $CIRCLE_ARTIFACTS is pointing to they’ll automatically show up in your build artifacts as well. Therefore the artifacts array is completely obsolete for this purpose, as the script will put the stdout at the right place.
So far this is the background of the error you’re facing, but not yet the answer to your question. What you try to achieve is running a background process that stores it’s output in the given artifacts directory. To run a background process you’ll have to specify the command, as well as the background flag, in the post array:
machine:
post:
- FILE=$CIRCLE_ARTIFACTS/memory-usage-actual.txt; while true; do ps -u ubuntu eo pid,%cpu,%mem,args,uname --sort=-%mem >> $FILE; echo "----------" >> $FILE; sleep 1; done:
background: true