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

Trying to run a DSC config from Github pipeline #5626

Closed
MarkLakatos opened this issue Jan 14, 2025 · 4 comments
Closed

Trying to run a DSC config from Github pipeline #5626

MarkLakatos opened this issue Jan 14, 2025 · 4 comments

Comments

@MarkLakatos
Copy link

Hello everyone!

I have a problem with deploying a configuration with github actions.
The code that throws the error:

  • name: Generate MOF File and Apply Configuration
    shell: pwsh
    run: |
    # Correct paths for configuration and data files
    $ConfigPath = "$(Get-Location)/First/M365TenantConfig.ps1"
    $ConfigDataPath = "$(Get-Location)/First/ConfigurationData.psd1"
    $MofOutputPath = "$(Get-Location)/First/M365TenantConfig"

        Write-Host "Generating MOF file and applying configuration..."
        & $ConfigPath
        Start-DscConfiguration -Path $MofOutputPath -Wait -Verbose
    

The error:
Generating MOF file and applying configuration...
M365TenantConfig.ps1: D:\a_temp\7545ee67-891b-40ea-871e-d193462856fe.ps1:8
Line |
8 | . $ConfigPath
| ~~~~~~~~~~~~~
| Cannot process argument transformation on parameter 'ConfigurationData'. Cannot find path
| 'D:\a\PRJ_Microsoft365_DSC_Repository\PRJ_Microsoft365_DSC_Repository\ConfigurationData.psd1' because it does
| not exist.
Error: Process completed with exit code 1.

Does anyone know what causes the issue and how can be resolved.
Thank you in advance!

@FabienTschanz
Copy link
Contributor

It seems like that in your M365TenantConfig.ps1, you have a reference to the ConfigurationData.psd1 file, but the path probably is incorrect. Both files should be in the same directory, with the last line in the M365TenantConfig.ps1 being something like M365TenantConfig -ConfigurationData .\ConfigurationData.psd1.

How does the directory structure look like in your case and both files? Is it possible for you to execute it locally?

@MarkLakatos
Copy link
Author

MarkLakatos commented Jan 15, 2025

Thank you for the answer!
I have changed the file quite a bit. I placed the Configuration data, the mof generation and deploymant inside the M365Tenantconfig file. The goal would be to run the whole thing manually from github actions.
Now it looks like this:
...The dsc configs
}
$CertPath = Join-Path -Path (Get-Location) -ChildPath "First\M365DSC.cer"
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = "Localhost"
PSDscAllowPlainTextPassword = $true;
PSDscAllowDomainUser = $true;
CertificateFile = $CertPath
ServerNumber = "0"
}
)
}
# Compile and deploy configuration
try
{
M365TenantConfig -ConfigurationData $ConfigurationData -Credential $CredsCredential
Start-DscConfiguration M365TenantConfig -Wait -Force -Verbose -ErrorAction Stop
}
catch
{
throw $_
}

So now it reaches the Mof file generation command, but it goes on indefinitely. Any idea what could cause this? What else can I share to help you see the problem better?

@FabienTschanz
Copy link
Contributor

A sample M365TenantConfig.ps1 would look like this for my case:

# Generated with Microsoft365DSC version 1.24.1218.1
# For additional information on how to use Microsoft365DSC, please visit https://aka.ms/M365DSC
param (
)

Configuration M365TenantConfig
{
    param (
    )

    $OrganizationName = $ConfigurationData.NonNodeData.OrganizationName

    Import-DscResource -ModuleName 'Microsoft365DSC' -ModuleVersion '1.24.1218.1'

    Node localhost
    {.
    ....
    }
}

M365TenantConfig -ConfigurationData .\ConfigurationData.psd1

In the same directory, I have a ConfigurationData.psd1 file with the following content:

@{
    AllNodes = @(
        @{
            NodeName                    = "localhost"
            PSDscAllowPlainTextPassword = $true;
            PSDscAllowDomainUser        = $true;
            #region Parameters
            # Default Value Used to Ensure a Configuration Data File is Generated
            ServerNumber = "0"

        }
    )
    NonNodeData = @(
        @{
            # Tenant's default verified domain name
            OrganizationName = "<your organization>.onmicrosoft.com"

            # Azure AD Application Id for Authentication
            ApplicationId = "<application id, or credential, whatever you like>"

            # The Id or Name of the tenant to authenticate against
            TenantId = "<same as your organization>.onmicrosoft.com"

            # Thumbprint of the certificate to use for authentication
            CertificateThumbprint = "<certificate thumbprint>"

        }
    )
}

To execute it, simply run M365TenantConfig.ps1. The Start-DscConfiguration command can only be applied to a already "built" configuration after executing the .ps1 file. Does that make any sense?

@MarkLakatos
Copy link
Author

Thank you for the answer again! The problem was that i had multiple parameters and it somhow interfered with the mof file generation.
All sorted now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants