|
6 | 6 | .Description |
7 | 7 | Registers an Azure DevOps artifact feed as a PowerShell Repository. |
8 | 8 | 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 |
9 | 11 | .Link |
10 | 12 | https://docs.microsoft.com/en-us/azure/devops/artifacts/tutorials/private-powershell-library?view=azure-devops |
11 | 13 | .Link |
|
21 | 23 | #> |
22 | 24 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", |
23 | 25 | Justification="Abstracting Credential Structure is part of the point")] |
| 26 | + [OutputType('Microsoft.PowerShell.Commands.PSRepository')] |
24 | 27 | param( |
25 | 28 | # The name of the organization. |
26 | 29 | [Parameter(Mandatory,ValueFromPipelineByPropertyName)] |
|
33 | 36 | $Project, |
34 | 37 |
|
35 | 38 | # The name or ID of the feed. |
36 | | - [Parameter(Mandatory,ValueFromPipelineByPropertyName)] |
37 | | - [Alias('fullyQualifiedId')] |
| 39 | + [Parameter(Mandatory,ValueFromPipelineByPropertyName)] |
38 | 40 | [string] |
39 | | - $FeedID, |
| 41 | + $Name, |
40 | 42 |
|
41 | 43 | # The personal access token used to connect to the feed. |
42 | 44 | [Parameter(ValueFromPipelineByPropertyName)] |
|
50 | 52 | $EmailAddress, |
51 | 53 |
|
52 | 54 | # 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 |
54 | 56 | [Parameter(ValueFromPipelineByPropertyName)] |
55 | 57 | [string] |
56 | 58 | $RepositoryName, |
57 | 59 |
|
58 | 60 | # 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 |
60 | 62 | [Parameter(ValueFromPipelineByPropertyName)] |
61 | 63 | [string] |
62 | 64 | $RepositoryUrl, |
|
73 | 75 | process { |
74 | 76 | #region Check if Repository Already Exists |
75 | 77 | $targetName = if ($RepositoryName) { $RepositoryName } |
76 | | - elseif ($Project) { "${Organization}-${Project}-${FeedID}" } |
77 | | - else { "${Organization}-${FeedID}" } |
| 78 | + elseif ($Project) { "${Organization}-${Project}-${Name}" } |
| 79 | + else { "${Organization}-${Name}" } |
78 | 80 | $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" } |
81 | 83 | $psRepoExists = $psRepos | |
82 | 84 | Where-Object { |
83 | 85 | $_.Name -eq $targetName -or |
|
109 | 111 | $repoCred = [Management.Automation.PSCredential]::new($EmailAddress, (ConvertTo-SecureString -AsPlainText -Force $PersonalAccessToken)) |
110 | 112 |
|
111 | 113 | Register-PSRepository -Name $targetName -SourceLocation $targetSource -PublishLocation $targetSource -InstallationPolicy Trusted -Credential $repoCred |
| 114 | + if ($?) { |
| 115 | + Get-PSRepository -Name $targetName |
| 116 | + } |
112 | 117 | #endregion Create Credential and Register-PSRepository |
113 | 118 | } |
114 | 119 | } |
0 commit comments