Skip to content

Instantly share code, notes, and snippets.

@cdhunt
Last active September 28, 2020 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdhunt/80984dea7c6e45f42badf6c7f7f7bd8f to your computer and use it in GitHub Desktop.
Save cdhunt/80984dea7c6e45f42badf6c7f7f7bd8f to your computer and use it in GitHub Desktop.
function New-PSRepositoryRequirement {
param (
[string]$Name,
[string]$Uri,
[string]$Policy = 'Trusted'
)
New-RequirementGroup 'Repository' -ScriptBlock {
@{
Describe = "$Name is registered"
Test = {
$repo = Get-PSRepository -Name $Name
$repo.SourceLocation -eq $Uri
}
Set = {
Register-PSRepository -Name $Name `
-SourceLocation $Uri `
-PublishLocation $Uri `
-InstallationPolicy $Policy
}
}
}.GetNewClosure()
}
function New-PSRepositoryRequirement {
param (
[string]$Name,
[string]$Uri,
[string]$Policy = 'Trusted'
)
New-RequirementGroup 'Repository' -ScriptBlock {
@{
Describe = "$Name is registered"
Test = {
$repo = Get-PSRepository -Name $Name
$repo.SourceLocation -eq $Uri
}
Set = {
Register-PSRepository -Name $Name `
-SourceLocation $Uri `
-PublishLocation $Uri `
-InstallationPolicy $Policy
}
}
}
}
& {New-PSRepositoryRequirement -Name artifactory -Uri https://url/artifactory/api/nuget/powershell}`
| Invoke-Requirement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment