Environment variables example not working #25708
-
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 ! |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
Environment variables are case-sensitive. Either the variables names in the |
Beta Was this translation helpful? Give feedback.
-
Its not working for me either, I thought it was me, but not sure it is anymore. ex. of my yaml name: build-test jobs: 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 ! |
Beta Was this translation helpful? Give feedback.
-
This is also not working for me. I can’t use environment variables at all in my .yml. |
Beta Was this translation helpful? Give feedback.
-
name: .NET Core # Trigger on push jobs: steps: - name: Setup .NET Core # This is not an official MsBuild action: https://github.com/topics/msbuild-action # Print the variables to ensure things are working properly Output: Run echo $BUILDMODE $GENERATEAPPINSTALLERFILE $RUNTIMEIDENTIFIER $TARGETPLATFORM 2 echo $BUILDMODE $GENERATEAPPINSTALLERFILE $RUNTIMEIDENTIFIER $TARGETPLATFORM |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Thanks Jherico! I completely forgot about the OS. The output is now correct: Run echo $env:BUILDMODE $env:GENERATEAPPINSTALLERFILE $env:RUNTIMEIDENTIFIER $env:TARGETPLATFORM |
Beta Was this translation helpful? Give feedback.
-
This works for me:
Credit to this article |
Beta Was this translation helpful? Give feedback.
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.