Upload files to "Powershell Modules & NuGet Repo"

This commit is contained in:
2026-07-01 19:01:44 +00:00
parent 1bcfc08926
commit 74ce3ee1a9
@@ -0,0 +1,58 @@
<#
Author: Gabe Kerntke
Date: 01/08/26
.Synopsis
Script for the CI/CD Pipeline to create and publish PowerShell modules.
.Modified
- GabeK (1/8/26): Script created
- GabeK (3/12/26): Updated to use Pipeline ID varable for versioning in manifest file.
#>
#Region New-Module_Manifest
function New-Module_Manifest {
$RootModule = Get-ChildItem -File -Filter *.psm1 -Recurse -ErrorAction Stop | Select-Object -First 1
$Path = [System.IO.Path]::ChangeExtension($RootModule.FullName, '.psd1')
$manifest = @{
Author = $GITLAB_USER_NAME
Description = $CI_PROJECT_DESCRIPTION
FunctionsToExport = @( $Function_Names )
Path = $Path
RootModule = $RootModule.Name
CompanyName = 'COMPANY'
LicenseUri = 'https://opensource.org/licenses/MIT'
ModuleVersion = $CI_PIPELINE_IID.0
CmdletsToExport = ''
AliasesToExport = ''
}
New-ModuleManifest @manifest
}
#EndRegion
#Region Start Script
$Test = Get-ChildItem -Path $SourceDirectory -Include *.psm1 -Recurse
If (Test-Path $Test) {
$Function_Names = Get-ChildItem -Recurse -Depth 2 -Filter *.psm1 | ForEach-Object {
# Extract function names from each .psm1 file
$tokens = $null; $errors = $null
$ast = [System.Management.Automation.Language.Parser]::ParseFile($_.FullName, [ref]$tokens, [ref]$errors)
$ast.FindAll(
{ param($n) $n -is [System.Management.Automation.Language.FunctionDefinitionAst] },
$true
).Name
} | Select-Object -Unique
}
else {
write-Output "No Module (.psm1) files found."
exit 1
}
New-Module_Manifest
Get-ChildItem -Path $SourceDirectory -Include *.psm1 -Recurse | ForEach-Object {
$Module = (Split-Path $_.FullName)
Write-Output "Publishing module $Module"
Publish-Module -Path "$Module" -Repository "${NUGET_REPOSITORY_ID}" -ErrorAction Stop -Force -Verbose -NuGetApiKey "${username}:${ARTIFACTORY_TOKEN}"
}
#Region End Script
#EndRegion