Bit late to the party, but the way I’ve escaped in the past is shown here: [Support Guide] Using an SSH key via environment variable during build
Environment variables with embedded carriage returns are pretty hard for the shell, so a pattern like this is preferred even outside of the netlify build shell