Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server 2016: Get-SamplerAbsolutePath not found #350

Closed
nyanhp opened this issue Feb 15, 2022 · 6 comments · Fixed by #369
Closed

Server 2016: Get-SamplerAbsolutePath not found #350

nyanhp opened this issue Feb 15, 2022 · 6 comments · Fixed by #369
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.

Comments

@nyanhp
Copy link

nyanhp commented Feb 15, 2022

Problem description

Running a build for https://github.com/dsccommunity/commontasks fails on a Server 2016, PowerShell 5.1.14393.0 because Get-SampleAbsolutePath could not be found. Examining the exported commands according to PowerShell, most exported functions are missing:

PS C:\AzureDevOpsAgents\DEV-1\_work\3\s> gcm -module sampler

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           Build-Module.ModuleBuilder.build.Sampler.ib.tasks  0.112.2    Sampler
Alias           Invoke-Pester.pester.build.Sampler.ib.tasks        0.112.2    Sampler
Alias           Set-BuildEnvironment.BuildHelpers.build.Sampler... 0.112.2    Sampler
Alias           Set-SamplerTaskVariable                            0.112.2    Sampler

Verbose logs

PS C:\AzureDevOpsAgents\DEV-1\_work\3\s> ipmo -verbose sampler -force
VERBOSE: Loading module from path
'C:\AzureDevOpsAgents\DEV-1\_work\3\s\output\RequiredModules\sampler\0.112.2\sampler.psd1'.
VERBOSE: Removing the imported "Build-Module.ModuleBuilder.build.Sampler.ib.tasks" alias.
VERBOSE: Removing the imported "ChocolateyPackage.build.Sampler.ib.tasks" alias.
VERBOSE: Removing the imported "Clean.ModuleBuilder.build.Sampler.ib.tasks" alias.
VERBOSE: Removing the imported "DeployAll.PSDeploy.build.Sampler.ib.tasks" alias.
VERBOSE: Removing the imported "DscResource.Test.build.Sampler.ib.tasks" alias.
VERBOSE: Removing the imported "generateHelp.PlatyPS.build.Sampler.ib.tasks" alias.
VERBOSE: Removing the imported "GuestConfig.build.Sampler.ib.tasks" alias.
VERBOSE: Removing the imported "Invoke-Pester.pester.build.Sampler.ib.tasks" alias.
VERBOSE: Removing the imported "JaCoCo.coverage.build.Sampler.ib.tasks" alias.
VERBOSE: Removing the imported "release.module.build.Sampler.ib.tasks" alias.
VERBOSE: Removing the imported "Set-BuildEnvironment.BuildHelpers.build.Sampler.ib.tasks" alias.
VERBOSE: Removing the imported "Set-SamplerTaskVariable" alias.
VERBOSE: Populating RepositorySourceLocation property for module sampler.
VERBOSE: Loading module from path
'C:\AzureDevOpsAgents\DEV-1\_work\3\s\output\RequiredModules\sampler\0.112.2\Sampler.psm1'.
VERBOSE: Importing alias 'Build-Module.ModuleBuilder.build.Sampler.ib.tasks'.
VERBOSE: Importing alias 'ChocolateyPackage.build.Sampler.ib.tasks'.
VERBOSE: Importing alias 'Clean.ModuleBuilder.build.Sampler.ib.tasks'.
VERBOSE: Importing alias 'DeployAll.PSDeploy.build.Sampler.ib.tasks'.
VERBOSE: Importing alias 'DscResource.Test.build.Sampler.ib.tasks'.
VERBOSE: Importing alias 'generateHelp.PlatyPS.build.Sampler.ib.tasks'.
VERBOSE: Importing alias 'GuestConfig.build.Sampler.ib.tasks'.
VERBOSE: Importing alias 'Invoke-Pester.pester.build.Sampler.ib.tasks'.
VERBOSE: Importing alias 'JaCoCo.coverage.build.Sampler.ib.tasks'.
VERBOSE: Importing alias 'release.module.build.Sampler.ib.tasks'.
VERBOSE: Importing alias 'Set-BuildEnvironment.BuildHelpers.build.Sampler.ib.tasks'.

How to reproduce

Windows Server 1607, clone repository, run build.ps1 -Resolve
Isolated, installing Plaster and Sampler, the problem can also be reproduced.

Expected behavior

Module can be imported without issues

Current behavior

Importing the module results in only a subset of functions and aliases being imported

Suggested solution

I don't have a suggested solution. Maybe update the list of requirements to include whatever this version of Windows might be missing?

Operating system the target node is running

OsName               : Microsoft Windows Server 2016 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsBuildLabEx    : 14393.0.amd64fre.rs1_release.160715-1616
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PowerShell version and build the target node is running

Name                           Value                                                                                   
----                           -----                                                                                   
PSVersion                      5.1.14393.0                                                                             
PSEdition                      Desktop                                                                                 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
BuildVersion                   10.0.14393.0                                                                            
CLRVersion                     4.0.30319.42000                                                                         
WSManStackVersion              3.0                                                                                     
PSRemotingProtocolVersion      2.3                                                                                     
SerializationVersion           1.1.0.1                                                                                 


.NET versions:
 Build Version
 ----- -------
 50727 2.0.50727.4927
 30729 3.0.30729.4926
 30729 3.5.30729.4926
528049 4.8

Module version used

Both versions showed the same issue:
Name    Version Path
----    ------- ----
Sampler 0.112.2 C:\AzureDevOpsAgents\DEV-1\_work\3\s\output\RequiredModules\Sampler\0.112.2\Sampler.psd1
Sampler 0.112.1 C:\AzureDevOpsAgents\DEV-1\_work\3\s\output\RequiredModules\Sampler\0.112.1\Sampler.psd1
@raandree
Copy link
Contributor

I have just tried that on a Windows Server 2016 box and it works as expected.

PS C:\Users\install> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.4583
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.4583
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
PS C:\Users\install> gcm -module sampler

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           Build-Module.ModuleBuilder.build.Sampler.ib.tasks  0.112.1    sampler
Alias           Invoke-Pester.pester.build.Sampler.ib.tasks        0.112.1    sampler
Alias           Set-BuildEnvironment.BuildHelpers.build.Sampler... 0.112.1    sampler
Alias           Set-SamplerTaskVariable                            0.112.1    sampler
Function        Add-Sample                                         0.112.1    sampler
Function        Convert-SamplerHashtableToString                   0.112.1    sampler
Function        Get-BuildVersion                                   0.112.1    sampler
Function        Get-BuiltModuleVersion                             0.112.1    sampler
Function        Get-ClassBasedResourceName                         0.112.1    sampler
Function        Get-CodeCoverageThreshold                          0.112.1    sampler
Function        Get-MofSchemaName                                  0.112.1    sampler
Function        Get-OperatingSystemShortName                       0.112.1    sampler
Function        Get-PesterOutputFileFileName                       0.112.1    sampler
Function        Get-SamplerAbsolutePath                            0.112.1    sampler
Function        Get-SamplerBuiltModuleBase                         0.112.1    sampler
Function        Get-SamplerBuiltModuleManifest                     0.112.1    sampler
Function        Get-SamplerCodeCoverageOutputFile                  0.112.1    sampler
Function        Get-SamplerCodeCoverageOutputFileEncoding          0.112.1    sampler
Function        Get-SamplerModuleInfo                              0.112.1    sampler
Function        Get-SamplerModuleRootPath                          0.112.1    sampler
Function        Get-SamplerProjectName                             0.112.1    sampler
Function        Get-SamplerSourcePath                              0.112.1    sampler
Function        Merge-JaCoCoReport                                 0.112.1    sampler
Function        New-SampleModule                                   0.112.1    sampler
Function        New-SamplerJaCoCoDocument                          0.112.1    sampler
Function        New-SamplerPipeline                                0.112.1    sampler
Function        Out-SamplerXml                                     0.112.1    sampler
Function        Split-ModuleVersion                                0.112.1    sampler
Function        Update-JaCoCoStatistic                             0.112.1    sampler

The build of CommonTasks works as expected.

@johlju johlju added the needs more information The issue needs more information from the author or the community. label Feb 15, 2022
@nyanhp
Copy link
Author

nyanhp commented Feb 18, 2022

@johlju I am unable to provide more information. The trace I ran is giving me no tangible information. The module works on my own clients without issues. It works on systems running Server 2019 and 2022 in the same offline environment. The only exception is that it only partially imports on Server 2016, 1607 as outlined above.

Trace.log from the system, for what it's worth.

I've tried different ways of installing sampler. The environment we are experiencing these issues is entirely offline. We:

  • Used Save-Module on my client and Publish-Module into an internal gallery, installed from there -> Failure
  • Copied the module that was installed on my system to the remote -> Failure

Since @raandree says it works on his system, I cannot really do much here. It is quite frustrating though. We have created a new agent pool with agents running Server 2022, but I feel that this behavior bears investigation. At the very least, some requirement may be undocumented, which never came up during testing.

@johlju johlju added needs investigation The issue needs to be investigated by the maintainers or/and the community. and removed needs more information The issue needs more information from the author or the community. labels Feb 18, 2022
@johlju
Copy link
Collaborator

johlju commented Feb 18, 2022

The aliases are imported through the psm1 script file (last in the file) while the other ones are exported through the module manifest. This issue might happen because (just guessing):

  • We are using Export-ModuleMember in the script file
  • The module manifest requires that Plaster module is available.

Does this issue happen when the Plaster module is not available? Or if we remove the Export-ModuleMember from the script file, does it export the other functions correctly?

@johlju
Copy link
Collaborator

johlju commented May 13, 2022

It looks like I hitting the same issue on a private build server for Windows PowerShell only (5.1.14409.1027) on a Windows Server 2012 R2 . 🤔 Please not that this does not happen on all machines with Windows PowerShell. It do work on the dev-machine, but not on the build server.

The build task Invoke_Pester_Tests_v5 calls the alias Set-SamplerTaskVariable which is exported by Sampler, but then it does not find the exported command Get-SamplerProjectName.

ERROR: The term 'Get-SamplerProjectName' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\vstsagent\_work\79\s\output\RequiredModules\Sampler\0.112.3\tasks\Invoke-Pester.pester.build.ps1:444 char:5
+     . Set-SamplerTaskVariable
+     ~~~~~~~~~~~~~~~~~~~~~~~~~
At D:\vstsagent\_work\79\s\output\RequiredModules\Sampler\0.112.3\tasks\Invoke-Pester.pester.build.ps1:422 char:1

Running Get-Command I only see the same four aliases that @nyanhp did.

@johlju
Copy link
Collaborator

johlju commented May 13, 2022

The problem is the Export-ModuleMember which is used here:

Export-ModuleMember -Alias $taskFileAliasName

and here:
Export-ModuleMember -Alias 'Set-SamplerTaskVariable'

Removing those two the aliases are still exported since all aliases are exported through module manifest:

AliasesToExport = '*'

Removing the Export-ModuleMember from the above two locations (in suffix.ps1) the module is exporting correctly and the task works as expected:

PS > get-command -module sampler -CommandType All

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           Build-Module.ModuleBuilder.build.Sampler.ib.tasks  0.112.3    Sampler
Alias           ChocolateyPackage.build.Sampler.ib.tasks -> Cho... 0.112.3    Sampler
Alias           Clean.ModuleBuilder.build.Sampler.ib.tasks -> C... 0.112.3    Sampler
Alias           DeployAll.PSDeploy.build.Sampler.ib.tasks -> De... 0.112.3    Sampler
Alias           DscResource.Test.build.Sampler.ib.tasks -> DscR... 0.112.3    Sampler
Alias           generateHelp.PlatyPS.build.Sampler.ib.tasks -> ... 0.112.3    Sampler
Alias           GuestConfig.build.Sampler.ib.tasks -> GuestConf... 0.112.3    Sampler
Alias           Invoke-Pester.pester.build.Sampler.ib.tasks        0.112.3    Sampler
Alias           JaCoCo.coverage.build.Sampler.ib.tasks -> JaCoC... 0.112.3    Sampler
Alias           release.module.build.Sampler.ib.tasks -> releas... 0.112.3    Sampler
Alias           Set-BuildEnvironment.BuildHelpers.build.Sampler... 0.112.3    Sampler
Alias           Set-SamplerTaskVariable                            0.112.3    Sampler
Function        Add-Sample                                         0.112.3    Sampler
Function        Convert-SamplerHashtableToString                   0.112.3    Sampler
Function        Get-BuildVersion                                   0.112.3    Sampler
Function        Get-BuiltModuleVersion                             0.112.3    Sampler
Function        Get-ClassBasedResourceName                         0.112.3    Sampler
Function        Get-CodeCoverageThreshold                          0.112.3    Sampler
Function        Get-MofSchemaName                                  0.112.3    Sampler
Function        Get-OperatingSystemShortName                       0.112.3    Sampler
Function        Get-PesterOutputFileFileName                       0.112.3    Sampler
Function        Get-SamplerAbsolutePath                            0.112.3    Sampler
Function        Get-SamplerBuiltModuleBase                         0.112.3    Sampler
Function        Get-SamplerBuiltModuleManifest                     0.112.3    Sampler
Function        Get-SamplerCodeCoverageOutputFile                  0.112.3    Sampler
Function        Get-SamplerCodeCoverageOutputFileEncoding          0.112.3    Sampler
Function        Get-SamplerModuleInfo                              0.112.3    Sampler
Function        Get-SamplerModuleRootPath                          0.112.3    Sampler
Function        Get-SamplerProjectName                             0.112.3    Sampler
Function        Get-SamplerSourcePath                              0.112.3    Sampler
Function        Merge-JaCoCoReport                                 0.112.3    Sampler
Function        New-SampleModule                                   0.112.3    Sampler
Function        New-SamplerJaCoCoDocument                          0.112.3    Sampler
Function        New-SamplerPipeline                                0.112.3    Sampler
Function        Out-SamplerXml                                     0.112.3    Sampler
Function        Split-ModuleVersion                                0.112.3    Sampler
Function        Update-JaCoCoStatistic                             0.112.3    SamplerAlias 

@johlju
Copy link
Collaborator

johlju commented May 13, 2022

This will be an issue in the future if a public command is aliased, then we have to work around a bug in ModuleBuilder by doing below, but we could just remove the Export-ModuleMember for now.
https://github.com/dsccommunity/DscResource.Test/blob/73d6c3290572a0b065084a1adcaa1eb5a8da5994/build.yaml#L34-L60

@johlju johlju added bug The issue is a bug. in progress The issue is being actively worked on by someone. and removed needs investigation The issue needs to be investigated by the maintainers or/and the community. labels May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants