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

Get-Psm1SchemaName: Fails to parse schema.psm1 correctly #410

Open
johlju opened this issue Jan 11, 2023 · 6 comments
Open

Get-Psm1SchemaName: Fails to parse schema.psm1 correctly #410

johlju opened this issue Jan 11, 2023 · 6 comments
Labels
enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community.

Comments

@johlju
Copy link
Collaborator

johlju commented Jan 11, 2023

Problem description

Fails to build the module in the pipeline if there is a composite resource.

Verbose logs

2023-01-10T15:46:43.7511363Z ===============================================================================
2023-01-10T15:46:43.7513500Z �[96m			BUILD DSCRESOURCESTOEXPORT MODULEBUILDER�[0m
2023-01-10T15:46:43.7532721Z �[90m�[0m
2023-01-10T15:46:43.7533635Z -------------------------------------------------------------------------------
2023-01-10T15:46:43.7535504Z �[90m  /pack/build/Build_Module_ModuleBuilder/Build_DscResourcesToExport_ModuleBuilder�[0m
2023-01-10T15:46:43.7537436Z �[90m  /home/vsts/work/1/s/output/RequiredModules/Sampler/0.116.1/tasks/Build-Module.ModuleBuilder.build.ps1:327�[0m
2023-01-10T15:46:43.7538670Z 
2023-01-10T15:46:43.7575233Z 	Project Name               = 'ConfigMgrCBDsc'
2023-01-10T15:46:43.7576148Z 	Source Path                = '/home/vsts/work/1/s/source'
2023-01-10T15:46:43.7578434Z 	Output Directory           = '/home/vsts/work/1/s/output'
2023-01-10T15:46:43.7582358Z 	Release Notes path         = '/home/vsts/work/1/s/output/ReleaseNotes.md'
2023-01-10T15:46:43.7586043Z 	Built Module Subdirectory  = '/home/vsts/work/1/s/output/'
2023-01-10T15:46:43.7595087Z 	Module Manifest Path (src) = '/home/vsts/work/1/s/source/ConfigMgrCBDsc.psd1'
2023-01-10T15:46:43.7622945Z 	Versioned Output Directory = 'True'
2023-01-10T15:46:43.7687382Z 	Built Module Manifest      = '/home/vsts/work/1/s/output/ConfigMgrCBDsc/3.1.0/ConfigMgrCBDsc.psd1'
2023-01-10T15:46:43.7710625Z 	Built Module Base          = '/home/vsts/work/1/s/output/ConfigMgrCBDsc/3.1.0'
2023-01-10T15:46:43.7795128Z 	Module Version             = '3.1.0-preview0003'
2023-01-10T15:46:43.7801002Z 	Module Version Folder      = '3.1.0'
2023-01-10T15:46:43.7807419Z 	Pre-release Tag            = 'preview0003'
2023-01-10T15:46:43.7847842Z 	Built Module Root Script   = ''
2023-01-10T15:46:43.7848022Z 
2023-01-10T15:46:43.7860075Z 	Built DSC Resource Path  = '/home/vsts/work/1/s/output/ConfigMgrCBDsc/3.1.0/DSCResources'
2023-01-10T15:46:43.7863135Z �[93mLooking for MOF-based DSC Resources in '/home/vsts/work/1/s/output/ConfigMgrCBDsc/3.1.0/DSCResources'�[0m
2023-01-10T15:46:44.0582609Z �[97m  Adding 'CMAccounts, CMAdministrativeUser, CMAssetIntelligencePoint, CMBoundaries, CMBoundaryGroups, CMClientPushSettings, CMClientSettings, CMClientSettingsBits, CMClientSettingsClientCache, CMClientSettingsClientPolicy, CMClientSettingsCloudService, CMClientSettingsCompliance, CMClientSettingsComputerAgent, CMClientSettingsComputerRestart, CMClientSettingsDelivery, CMClientSettingsHardware, CMClientSettingsMetered, CMClientSettingsPower, CMClientSettingsRemoteTools, CMClientSettingsSoftwareCenter, CMClientSettingsSoftwareDeployment, CMClientSettingsSoftwareInventory, CMClientSettingsSoftwareMetering, CMClientSettingsSoftwareUpdate, CMClientSettingsStateMessaging, CMClientSettingsUserDeviceAffinity, CMClientStatusSettings, CMCollectionMembershipEvaluationComponent, CMCollections, CMDistributionGroup, CMDistributionPoint, CMDistributionPointGroupMembers, CMEmailNotificationComponent, CMFallbackStatusPoint, CMFileReplication, CMForestDiscovery, CMGroupDiscovery, CMHeartbeatDiscovery, CMHierarchySetting, CMIniFile, CMMaintenanceWindows, CMManagementPoint, CMNetworkDiscovery, CMPullDistributionPoint, CMPxeDistributionPoint, CMReportingServicePoint, CMSecurityRoles, CMSecurityScopes, CMServiceConnectionPoint, CMSiteConfiguration, CMSiteMaintenance, CMSiteSystemServer, CMSoftwareDistributionComponent, CMSoftwareUpdatePoint, CMSoftwareUpdatePointComponent, CMStatusReportingComponent, CMSystemDiscovery, CMUserDiscovery' to the list of DscResource will be write in module manifest.�[0m
2023-01-10T15:46:44.0589040Z �[93mLooking for DSC Composite Resources in '/home/vsts/work/1/s/output/ConfigMgrCBDsc/3.1.0/DSCResources'�[0m
2023-01-10T15:46:44.1196259Z �[91mERROR: It is expected to find only 1 configuration in the file '/home/vsts/work/1/s/output/ConfigMgrCBDsc/3.1.0/DSCResources/xSccmInstall/xSccmInstall.schema.psm1' but found 0�[0m
2023-01-10T15:46:44.1197914Z �[91mAt /home/vsts/work/1/s/output/RequiredModules/Sampler/0.116.1/tasks/Build-Module.ModuleBuilder.build.ps1:399 char:62�[0m
2023-01-10T15:46:44.1199003Z �[91m+ … urcesNames = $mofPath.FullName | Get-Psm1SchemaName -ErrorAction Stop�[0m
2023-01-10T15:46:44.1200143Z �[91m+                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~�[0m
2023-01-10T15:46:44.1205889Z �[90mAt /home/vsts/work/1/s/output/RequiredModules/Sampler/0.116.1/tasks/Build-Module.ModuleBuilder.build.ps1:327 char:1�[0m
2023-01-10T15:46:44.1207016Z �[90m+ Task Build_DscResourcesToExport_ModuleBuilder {�[0m
2023-01-10T15:46:44.1207917Z �[90m+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~�[0m
2023-01-10T15:46:44.1367341Z �[91mBuild FAILED. 6 tasks, 1 errors, 0 warnings 00:00:02.9277358�[0m
2023-01-10T15:46:44.1999709Z �[31;1mGet-Psm1SchemaName: �[0m/home/vsts/work/1/s/output/RequiredModules/Sampler/0.116.1/tasks/Build-Module.ModuleBuilder.build.ps1:399
2023-01-10T15:46:44.2000511Z �[36;1mLine |
2023-01-10T15:46:44.2001216Z �[36;1m 399 | �[0m … urcesNames = $mofPath.FullName | �[36;1mGet-Psm1SchemaName -ErrorAction Stop�[0m
2023-01-10T15:46:44.2002006Z �[36;1m     | �[31;1m                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2023-01-10T15:46:44.2002795Z �[31;1m�[36;1m     | �[31;1mIt is expected to find only 1 configuration in the file
2023-01-10T15:46:44.2003712Z �[36;1m     | �[31;1m'/home/vsts/work/1/s/output/ConfigMgrCBDsc/3.1.0/DSCResources/xSccmInstall/xSccmInstall.schema.psm1' but found 0
2023-01-10T15:46:44.2004334Z �[0m
2023-01-10T15:46:44.2954842Z ##[error]PowerShell exited with code '1'.
2023-01-10T15:46:44.2988300Z ##[section]Finishing: Build & Package Module

How to reproduce

Run build on https://github.com/dsccommunity/ConfigMgrCBDsc with Sampler v0.116.1.

Fails on:

<#
    .SYNOPSIS
        A DSC composite resource to install SCCM.

    .PARAMETER SetupExePath
        Specifies the path to the setup.exe for SCCM.

    .PARAMETER IniFile
        Specifies the path of the ini file, to include the filename.

    .PARAMETER SccmServerType
        Specifies the SCCM Server type install, CAS or Primary.

    .PARAMETER SccmInstallAccount
        Specifies the credentials to use for the SCCM install.

    .PARAMETER Version
        Specifies the version of SCCM that will be installed.
#>
Configuration xSCCMInstall
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [System.String]
        $SetupExePath,

        [Parameter(Mandatory = $true)]
        [System.String]
        $IniFile,

        [Parameter(Mandatory = $true)]
        [ValidateSet('CAS', 'Primary')]
        [System.String]
        $SccmServerType,

        [Parameter(Mandatory = $true)]
        [System.Management.Automation.PSCredential]
        $SccmInstallAccount,

        [Parameter(Mandatory = $true)]
        [ValidateSet('1902', '1906', '1910', '2002', '2006', '2010')]
        [UInt32]
        $Version
    )

    Import-DscResource -ModuleName PSDesiredStateConfiguration

    if ($Version -lt 1910)
    {
        $prefix = 'System Center'
    }
    else
    {
        $prefix = 'Microsoft Endpoint'
    }

    if ($SccmServerType -eq 'CAS')
    {
        $productName = "$prefix Configuration Manager Central Administration Site Setup"
    }
    if ($SccmServerType -eq 'Primary')
    {
        $productName = "$prefix Configuration Manager Primary Site Setup"
    }

    Package SCCM
    {
        Ensure               = 'Present'
        Path                 = "$SetupExePath\Setup.exe"
        Name                 = $productName
        ProductId            = ''
        Arguments            = "/SCRIPT $IniFile"
        DependsOn            = $dependsOnChain
        PsDscRunAsCredential = $SccmInstallAccount
    }
}

Expected behavior

Build without failing.

Current behavior

Throws exception

ERROR: It is expected to find only 1 configuration in the file '/home/vsts/work/1/s/output/ConfigMgrCBDsc/3.1.0/DSCResources/xSccmInstall/xSccmInstall.schema.psm1' but found 0
At /home/vsts/work/1/s/output/RequiredModules/Sampler/0.116.1/tasks/Build-Module.ModuleBuilder.build.ps1:399 char:62

Suggested solution

Verify that the public command works as expected, and throw if there is an issue using it cross-platform.

Operating system the target node is running

Ubuntu 20.04.5 LTS
macOS

not tested on Windows.

PowerShell version and build the target node is running

Ubuntu: unknown
macOS: 7.3.1

Module version used

v0.116.1
@johlju
Copy link
Collaborator Author

johlju commented Jan 11, 2023

This is a bug on Linux and macOS. It works on Windows. So the command should probably fail if it can't parse configurations on a specifc OS.

@raandree
Copy link
Contributor

The issue happens in Get-Psm1SchemaName when calling $ast.FindAll. The parser fails with this error:

System.IO.DirectoryNotFoundException: Unable to find DSC schema store at /etc/opt/omi/conf/dsc/configuration. Please ensure PS DSC for Linux is installed.

If seems to be a well known issue since quite a while: PowerShell/PowerShell#10782.

@johlju
Copy link
Collaborator Author

johlju commented Jan 12, 2023

Yes it seems that the build worker "ubuntu 20.04" in Azure Pipelines change so that in no longer can parse the configurations. Guessing probably because PS was updated.
Quickest solution is to move build phase to run on vm image "windows-latest".

@johlju
Copy link
Collaborator Author

johlju commented Jan 12, 2023

But I think we should catch and throw the parse error so it's clear why it fails to find a configuration statement 🤔

@raandree
Copy link
Contributor

Right, happy to take care of it.

@johlju johlju added enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community. labels Jan 13, 2023
@johlju
Copy link
Collaborator Author

johlju commented Jan 13, 2023

@raandree great! I review as soon I see the PR is there. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

No branches or pull requests

2 participants