Skip to content

Commit ad83116

Browse files
Register-ADOArtifactFeed: Making -FeedID -Name. Adding examples. Static Analysis cleanup.
1 parent 5b55cd7 commit ad83116

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

Register-ADOArtifactFeed.ps1

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
.Description
77
Registers an Azure DevOps artifact feed as a PowerShell Repository.
88
thThis allows Install-Module, Publish-Module, and Save-Module to work against an Azure DevOps artifact feed.
9+
.Example
10+
Register-ADOArtifactFeed -Organization MyOrg -Project MyProject -Name MyFeed -PersonalAccessToken $myPat
911
.Link
1012
https://docs.microsoft.com/en-us/azure/devops/artifacts/tutorials/private-powershell-library?view=azure-devops
1113
.Link
@@ -21,6 +23,7 @@
2123
#>
2224
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "",
2325
Justification="Abstracting Credential Structure is part of the point")]
26+
[OutputType('Microsoft.PowerShell.Commands.PSRepository')]
2427
param(
2528
# The name of the organization.
2629
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
@@ -33,10 +36,9 @@
3336
$Project,
3437

3538
# The name or ID of the feed.
36-
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
37-
[Alias('fullyQualifiedId')]
39+
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
3840
[string]
39-
$FeedID,
41+
$Name,
4042

4143
# The personal access token used to connect to the feed.
4244
[Parameter(ValueFromPipelineByPropertyName)]
@@ -50,13 +52,13 @@
5052
$EmailAddress,
5153

5254
# If provided, will create a repository source using a given name.
53-
# By default, the RepositoryName will be $Organization-$Project-$FeedID
55+
# By default, the RepositoryName will be $Organization-$Project-$Name
5456
[Parameter(ValueFromPipelineByPropertyName)]
5557
[string]
5658
$RepositoryName,
5759

5860
# If provided, will create a repository using a given URL.
59-
# By default, the RepositoryURL is predicted using -Organization, -Project, and -FeedID
61+
# By default, the RepositoryURL is predicted using -Organization, -Project, and -Name
6062
[Parameter(ValueFromPipelineByPropertyName)]
6163
[string]
6264
$RepositoryUrl,
@@ -73,11 +75,11 @@
7375
process {
7476
#region Check if Repository Already Exists
7577
$targetName = if ($RepositoryName) { $RepositoryName }
76-
elseif ($Project) { "${Organization}-${Project}-${FeedID}" }
77-
else { "${Organization}-${FeedID}" }
78+
elseif ($Project) { "${Organization}-${Project}-${Name}" }
79+
else { "${Organization}-${Name}" }
7880
$targetSource = if ($RepositoryUrl) { $RepositoryUrl }
79-
elseif ($Project) { "https://pkgs.dev.azure.com/$Organization/$Project/_packaging/$FeedID/nuget/v2" }
80-
else { "https://pkgs.dev.azure.com/$Organization/_packaging/$FeedID/nuget/v2" }
81+
elseif ($Project) { "https://pkgs.dev.azure.com/$Organization/$Project/_packaging/$Name/nuget/v2" }
82+
else { "https://pkgs.dev.azure.com/$Organization/_packaging/$Name/nuget/v2" }
8183
$psRepoExists = $psRepos |
8284
Where-Object {
8385
$_.Name -eq $targetName -or
@@ -109,6 +111,9 @@
109111
$repoCred = [Management.Automation.PSCredential]::new($EmailAddress, (ConvertTo-SecureString -AsPlainText -Force $PersonalAccessToken))
110112

111113
Register-PSRepository -Name $targetName -SourceLocation $targetSource -PublishLocation $targetSource -InstallationPolicy Trusted -Credential $repoCred
114+
if ($?) {
115+
Get-PSRepository -Name $targetName
116+
}
112117
#endregion Create Credential and Register-PSRepository
113118
}
114119
}

0 commit comments

Comments
 (0)