Environment variables example not working

So I was reading docs and came to part of environment variable https://help.github.com/en/articles/virtual-environments-for-github-actions#environment-variables . When I copy pasted given example and run actions why given example is not working?. It is displaying Hello World ! but it should have displayed Hello World Mona The Octocat !

3 Likes

Environment variables are case-sensitive. Either the variables names in the env key need to be uppercase or the env substitution in the run key need to be lowercase.

1 Like

Its not working for me either, I thought it was me, but not sure it is anymore. ex. of my yaml

name: build-test
on: [pull_request]

jobs:
  build_database:
    runs-on: self-hosted
    
    steps:
    - name: Hello world
      run: echo Hello world $FIRST_NAME $middle_name $Last_Name!
      env:
        FIRST_NAME: Mona
        middle_name: The
        Last_Name: Octocat

Ex: of the output

 Hello world

5s

Run echo Hello world $FIRST_NAME $middle_name $Last_Name!

echo Hello world $FIRST_NAME $middle_name $Last_Name!

shell: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.EXE -command ‚Äú. ‚Äė{0}‚Äô‚ÄĚ

env:

FIRST_NAME: Mona

middle_name: The

Last_Name: Octocat

Hello

world

!

1 Like

This is also not working for me.  I can’t use environment variables at all in my .yml.

name: .NET Core

# Trigger on push
on: [push]

jobs:
  build:
  
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v1

    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
¬†¬†¬†¬†¬†¬†¬†¬†dotnet-version:¬†‚Äė3.0.100‚Äô

    # This is not an official MsBuild action:  https://github.com/topics/msbuild-action
    - name: Setup MSBuild.exe
      uses: warrenbuckley/Setup-MSBuild@v1

    # Print the variables to ensure things are working properly
    - name: Print
      env:
        BUILDMODE: SideLoadOnly
        CONFIGURATION: Release
        DISTRIBUTIONURL: \ddfiles\team\xaml\user\edskrod
        GENERATEAPPINSTALLERFILE: true
        RUNTIMEIDENTIFIER: win-x86
        TARGETPLATFORM: x86
      run: echo $BUILDMODE $GENERATEAPPINSTALLERFILE $RUNTIMEIDENTIFIER $TARGETPLATFORM

Output:

Run echo $BUILDMODE $GENERATEAPPINSTALLERFILE $RUNTIMEIDENTIFIER $TARGETPLATFORM

2 echo $BUILDMODE $GENERATEAPPINSTALLERFILE $RUNTIMEIDENTIFIER $TARGETPLATFORM
3 shell: C:\Program Files\PowerShell\6\pwsh.EXE -command ‚Äú. ‚Äė{0}‚Äô‚ÄĚ
4 env:
5 DOTNET_ROOT: C:\hostedtoolcache\windows\dncs\3.0.100\x64
6 BUILDMODE: SideLoadOnly
7 CONFIGURATION: Release
8 DISTRIBUTIONURL: \ddfiles\team\xaml\user\edskrod
9 GENERATEAPPINSTALLERFILE: true
10 RUNTIMEIDENTIFIER: win-x86
11 TARGETPLATFORM: x86

Different shells have different syntax for accessing environment variables, and different OSes have different default shells.

Assuming an environment variable named FOO, the $FOO syntax works only on the bash shell.

If you’re running on windows, the default shell is powershell, and the syntax would be $env:FOO

Alternatively, if you want your workflow to support multiple OSes, and want to use environment variables in the commadn line without changes between OSes, then you should explicitly specify the shell as bash.

3 Likes

Thanks Jherico!

I completely forgot about the OS.  The output is now correct:

 Run echo $env:BUILDMODE $env:GENERATEAPPINSTALLERFILE $env:RUNTIMEIDENTIFIER $env:TARGETPLATFORM
12  SideLoadOnly
13  true
14  win-x86
15   x86

1 Like