Skip to content

Set ENV Variable Using Github Action Workflow CMD #25993

Discussion options

You must be logged in to vote

@varunsridharan,

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'

multi_line="${multi_line//'%'/'%25'}"
multi_line="${multi_line//$'\n'/'%0A'}"
multi_line="${multi_line//$'\r'/'%0D'}"

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"

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants