Skip to content

Instantly share code, notes, and snippets.

@Xainey
Created June 17, 2016 15:52
Show Gist options
  • Select an option

  • Save Xainey/0e25dc501e5b6e04a86d92def19edf5f to your computer and use it in GitHub Desktop.

Select an option

Save Xainey/0e25dc501e5b6e04a86d92def19edf5f to your computer and use it in GitHub Desktop.
SMB Powershell-NuGet Module Share using Jenkins
<#
.Example
Import-Module -Name BuildHelpers
Set-BuildEnvironment
$ModuleInfo = @{
RepoName = 'PoshRepo'
RepoPath = '\\server\PoshRepo'
ModuleName = 'BuildHelpersTest'
ModulePath = '.\BuildHelpersTest.psd1'
}
Publish-SMBModule @ModuleInfo
#>
function Publish-SMBModule
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true)]
[string] $RepoName,
[Parameter(Mandatory=$true)]
[string] $RepoPath,
[Parameter(Mandatory=$true)]
[string] $ModuleName,
[Parameter(Mandatory=$true)]
[string] $ModulePath
)
# Resister SMB Share as Repository
if(!(Get-PSRepository -Name $RepoName -ErrorAction SilentlyContinue))
{
Register-PSRepository -Name $RepoName -SourceLocation $RepoPath -InstallationPolicy Trusted
}
# Update Existing Manifest
# - Source Manifest controls Major/Minor
# - Jenkins Controls Build Number.
if(Find-Module -Repository $RepoName -Name $ModuleName -ErrorAction SilentlyContinue)
{
$version = (Get-Module -FullyQualifiedName $ModulePath -ListAvailable).Version | Select Major, Minor
$newVersion = New-Object Version -ArgumentList $version.major, $version.minor, $ENV:BHBuildNumber
Update-ModuleManifest -Path $ModulePath -ModuleVersion $newVersion
}
# Publish ModuleInfo
# - Fails if nuget install needs confirmation in NonInteractive Mode.
try
{
$env:PSModulePath += ";$PSScriptRoot"
Publish-Module -Repository $RepoName -Name $ModuleName
}
catch [System.Exception]
{
Write-Error "Publish Failed"
throw($_.Exception)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment