Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Pilot Lvl 1
Message 1 of 3

Windows image bloat in PATH disables cmd-prompt usage

The windows images are full of preinstalled software that pollutes the PATH environment variable.

cmd.exe limits PATH to ~2000 characters, anything above is truncated.

Yes PowerShell is great but incidently Microsoft ships .bat-scripts as official way to setup the build environment for Visual Studio from the command line.

Also in our case we maintain and test a technology that uses and requires cmd.

I haven't found a way to clear the environment via env:, setx etc. as the current script is not affected.

 

We would preffer a Windows image with minimal preinstalled software.

As workaround we use Docker but it requires many additional steps.

 

Thanks for listening.

2 Replies
GitHub Staff
Message 2 of 3

Re: Windows image bloat in PATH disables cmd-prompt usage

Appreciate the feedback.  It's quite labor intensive to maintain build images, and we'd like to reduce the number of options available, for simplicity of selection.  But we'll keep this in mind.

 

In the meantime, you should be able to update the PATH environment variable.

 

`setx` updates the registry settings for what it calls the "master environment".  Unfortunately, it doesn't go into a lot of details as to what that really means, except in the content of "future command windows", so it's rather vague about what happens when you don't have a window at all!  But subsequent `run` steps will not consult that registry setting.

 

You can control the environment by using the set-env command, which future steps will obey.  For example, to strip the PATH environment variable down to just two directories:

 

    - run: echo "::set-env name=PATH::C:\Windows\System32;C:\Windows"
    - run: |
        # show the environment variables
        set
      shell: cmd

 

Pilot Lvl 1
Message 3 of 3

Re: Windows image bloat in PATH disables cmd-prompt usage

Hi,

Thanks for the quick response!

Indeed the suggested way will solve the problem for immediate calls, howerever it still is an issue for our system.

The system is called "rez" https://github.com/nerdvegas/rez and is an environment management system used throughout the visual effects and animation industry.

 

It is assuming a "clean" PATH environment by checking the registry directly:

https://github.com/nerdvegas/rez/blob/master/src/rezplugins/shell/cmd.py#L85

 

Hence my attempts to utilize setx. In our github actions we couldn't find a way to clean the environment on this level regardless of the attempts:

 

     - name: Prune environment
        run: |
          echo "::set-env name=PATH::C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\curl-7.65.0-win64-mingw\bin;C:\Program Files\dotnet\;C:\Program Files\7-Zip;C:\ProgramData\chocolatey\bin;C:\Program Files\PowerShell\6\;"
          cmd /C setx PATH "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\curl-7.65.0-win64-mingw\bin;C:\Program Files\dotnet\;C:\Program Files\7-Zip;C:\ProgramData\chocolatey\bin;C:\Program Files\PowerShell\6\;"
          cmd /C setx /m PATH "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\curl-7.65.0-win64-mingw\bin;C:\Program Files\dotnet\;C:\Program Files\7-Zip;C:\ProgramData\chocolatey\bin;C:\Program Files\PowerShell\6\;"
          ${Env:PATH} = "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\curl-7.65.0-win64-mingw\bin;C:\Program Files\dotnet\;C:\Program Files\7-Zip;C:\ProgramData\chocolatey\bin;C:\Program Files\PowerShell\6\;"

 

Imagine that afterwards we construct a subprocess with the PATH from the registry environment and run with cmd. At this point it truncates and fails our tests.

 

So far we were able to reconstruct a clean image from docker and run there with all the extra problems involved.

 

My originial point still stands: Any software relying on the system's (vs. process) PATH environment will fail in github actions on windows within the CMD-shell, due to the overly poluted PATH variable.

 

I wish that instead of what we have right now the images would start with a clean PATH (in the system) and define aliases or similar to opt-in certain products at runtime. It feels that this is easier to control an reason about.

 

I hope there is another solution that would work in our case, else we probably have to roll with docker and will try GH's new registry BETA. A pitty though.

 

Thanks again for your time.