Skip to content

Instantly share code, notes, and snippets.

@PureKrome
Created August 4, 2022 13:16
Show Gist options
  • Save PureKrome/494a11c9d354b3a5d0f24ccd05043513 to your computer and use it in GitHub Desktop.
Save PureKrome/494a11c9d354b3a5d0f24ccd05043513 to your computer and use it in GitHub Desktop.
Github custom environment variables - how each shell does this differently

With Github actions, each 'shell' has a different way of setting environment variables.

here's a list

credit/reference: https://webcache.googleusercontent.com/search?q=cache:PROV3eaERUkJ:https://github.community/t/environment-variable-setup-from-windows-runner/139296+&cd=4&hl=en&ct=clnk&gl=au


env: MSG: Hello jobs: print_env_var: name: Print environment variable runs-on: windows-latest steps: - name: Print environment variable with cmd run: echo "String matches %MSG%" shell: cmd

- name: Print environment variable with powershell 
  run: echo "String matches $env:MSG"
  shell: powershell

- name: Print environment variable with bash 
  run: echo "String matches $MSG"
  shell: bash

- name: Print environment variable with pwsh 
  run: echo "String matches ${env:MSG}"  # Use $env:MSG also can work
  shell: pwsh

- name: Print environment variable with python
  run: |
    import os
    print("String matches", os.environ['MSG'])
  shell: python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment