Set ENV Variable Using Github Action Workflow CMD

Hi There

i am currently working on a simple github action for my personal use in which i need to set some ENV Variable on the go. (Fully Dynamic) and if its a simple string it works great when i use

::set-env name=${key}::${value}

but thats not the case here

i need to create below YAML Env content dynamically using PHP

  VAR1: |

in the above example you can see i have used | to enter multi line values.

As of now using PHP i was able to set variables if its a single line values


::set-env name=VAR1::VALUE1

but if i try like this

::set-env name=VAR2::|

My other action is able to read only the | not the full string :frowning:


If you use the “set-env” command to set an environment variable with multi-line value, you need to escape the characters ‘%’, ‘\n’ and ‘\r’ in the value before passing it to the new environment variable. The runner will unescape in reverse.
A simple demo as reference:

- name: set env
  shell: bash
  run: |        
    multi_line="Line 01
    Line 02
    Line 03"

# escape the characters '%', '\n' and '\r'

# pass the value to the new environment variable
    echo "::set-env name=MY_ENV::$multi_line"

- name: print env
  shell: bash
  run: echo "$MY_ENV"