Env is null on windows operating-system

Was trying many stuff out and it was allways null, so this is what i get as a output

$COMPONENTS.Split(",") | ForEach {
    echo ::group::$_
    cd $_
    composer validate --strict
    $COMPOSER_UP
    $PHPUNIT
    cd $GITHUB_WORKSPACE
    echo ::endgroup::
  }
  shell: C:\windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command "& '{0}'"
  env:
    PHPUNIT: ./vendor/bin/phpunit --verbose
    COMPOSER_UP: composer update --no-progress --no-suggest --no-interaction --prefer-source --ansi
    COMPONENTS: src/Viserio/Bridge/Dotenv,src/Viserio/Bridge/Monolog,src/Viserio/Bridge/Phpstan,src/Viserio/Bridge/Twig,src/Viserio/Component/Bus,src/Viserio/Component/Cache,src/Viserio/Component/Config,src/Viserio/Component/Console,src/Viserio/Component/Container,src/Viserio/Component/Cookie,src/Viserio/Component/Cron,src/Viserio/Component/Events,src/Viserio/Component/Exception,src/Viserio/Component/Filesystem,src/Viserio/Component/Foundation,src/Viserio/Component/Http,src/Viserio/Component/HttpFactory,src/Viserio/Component/HttpFoundation,src/Viserio/Component/Log,src/Viserio/Component/Mail,src/Viserio/Component/Manager,src/Viserio/Component/OptionsResolver,src/Viserio/Component/Pagination,src/Viserio/Component/Parser,src/Viserio/Component/Pipeline,src/Viserio/Component/Profiler,src/Viserio/Component/Routing,src/Viserio/Component/Session,src/Viserio/Component/Support,src/Viserio/Component/Translation,src/Viserio/Component/Validation,src/Viserio/Component/View,src/Viserio/Component/WebServer,src/Viserio/Contract,src/Viserio/Provider/Debug,src/Viserio/Provider/Twig,
You cannot call a method on a null-valued expression.
At D:\a\_temp\b55bfeae-b30e-47b9-bd7c-bf4260f9a396.ps1:3 char:1
+ $COMPONENTS = $env.COMPONENTS.TrimEnd(",")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvokeMethodOnNull

##[error]Process completed with exit code 1.

I tryed $env.COMPONENTS and $COMPONENTS but it is always null, but in the env output its there.

Link to the file https://github.com/narrowspark/framework/blob/ecd4759b173f35d0c177ce703eb1ae09ff41f29f/.github/workflows/continuous-integration.yml#L176 hope someone has a idea

When you choose windows runner and run scripts with powershell, you can use ${env:var_name}  to use environment variables. 

ps_env.png

There is my example:

Please refer to this document:

https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#example-running-a-script-using-powershell-core

2 Likes