Tag Archives: Error: Unable to process file command ‘env’ successfully.

[Solved] Github Action Error: Error: Unable to process file command ‘env’ successfully.

I need to read text from a local file, usually in bash execution cat ./fileName, so I took it for granted

echo "FILE_TEXT=$(cat ./file.txt)" >> $GITHUB_ENV

Then report the error as follows

Error: Unable to process file command 'env' successfully.
Error: Invalid environment variable format 'xxxxxxxxxx... '

The reason is because setting $GITHUB_ENVthe environment variable does not directly support multiple lines of text, plus get EOFthe job
following this set on it

name: "Read the text"
run: |
       echo 'FILE_TEXT<<EOF' >> $GITHUB_ENV
       cat ./file.txt >> $GITHUB_ENV
       echo 'EOF' >> $GITHUB_ENV

run: |It is to run multi-line shell commands. Local variables can be obtained in this step. Those who need to obtain values ​​across steps must be written $GITHUB_ENVto, and then the reading method is as follows:

${{env.FILE_TEXT}}