Habitat studio build in newer versions results in Powershell Management Module errors

So I’ve been working on this automated build through Jenkins, running a build seems to cause this to happen to every single Windows package Jenkins tries to build using the Habitat plugin (which just runs a hab studio build habitat-win on the folder.

Get-Location : The 'Get-Location' command was found in the module 'Microsoft.PowerShell.Management', but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Management'.
At C:\hab\pkgs\core\hab-studio\0.73.0\20190115010701\bin\hab-studio.ps1:460 char:22
+   $script:SRC_PATH = Get-Location
+                      ~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Get-Location:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Any ideas as to why it wouldn’t be able to find this module? I reverted back to 0.65.0 at one point and this error stopped happening after deleting the later versions of hab-studio from the pkgs directory. Unfortunately that seems to trigger another error where hab keeps looking for C:/Windows/TEMP/hab. Any ideas as to why this may be happening?

Interesting. That line of the Studio code runs very early on and before we spawn Powershell Core. So it runs on the machine’s native Windows Powershell. I would say there is something environmentally wrong if it cannot load Microsoft.PowerShell.Management. I’m not sure why reverting to 0.65 helps since that has effectively the same code.

I wondering if something on the Jenkins node is manipulating the PSModulePath but perhaps that is not this issue since the error seems to indicate that it sees a module but just cannot load it. Unless it is pointing to an altered PSModulePath with maybe a powershell core version of Microsoft.PowerShell.Management.

The PSModulePath is never touched by Jenkins based on the Jenkinsfile I’m looking at. I’m not exactly sure why this is popping up on other versions besides 0.65 though. 0.71, 0.72 and 0.73 all cause the same problem.

Actually this makes a bit more sense now that I am reviewing/remembering some code. We actually do run that code in Powershell Core. In v0.68 we bumped to powershell core 6.1.0 (from 6.0.0). So if that bump is at fault then you should see things behave at 0.67 and break in 0.68. We have not seen any other reports of this problem so we would have to do some research to determine why it is breaking for you. If you could confirm things break on 0.68, could you file an issue over at https://github.com/habitat-sh/habitat?

Hey @mwrock! I can confirm that this is the case. 0.67 does still work while 0.68 seems to break in the same way I listed above. I’ll go ahead and file an issue.