Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 7

Environment variables example not working

Solved! Go to Solution.

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 !

6 Replies
Copilot Lvl 3
Message 2 of 7

Re: Environment variables example not working

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.

Ground Controller Lvl 2
Message 3 of 7

Re: Environment variables example not working

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
!
Copilot Lvl 2
Message 4 of 7

Re: Environment variables example not working

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

Copilot Lvl 2
Message 5 of 7

Re: Environment variables example not working

name.NET Core

 

# Trigger on push
on: [push]

 

jobs:
  build:
  
    runs-onwindows-latest

 

    steps:
    - usesactions/checkout@v1

 

    - nameSetup .NET Core
      usesactions/setup-dotnet@v1
      with:
        dotnet-version'3.0.100'

 

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

 

    # Print the variables to ensure things are working properly
    - namePrint
      env:
        BUILDMODESideLoadOnly
        CONFIGURATIONRelease
        DISTRIBUTIONURL\\ddfiles\team\xaml\user\edskrod
        GENERATEAPPINSTALLERFILEtrue
        RUNTIMEIDENTIFIERwin-x86
        TARGETPLATFORMx86
      runecho $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

Solution
Pilot Lvl 1
Message 6 of 7

Re: Environment variables example not working

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.

Copilot Lvl 2
Message 7 of 7

Re: Environment variables example not working

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