Added initial Publish-AzDOArtifactFeed.ps1 script
0603d5b3
Adam Rush
committed
1 changed file
Publish-AzDOArtifactFeed.ps1
/Build/Publish-AzDOArtifactFeed.ps1+73
/Build/Publish-AzDOArtifactFeed.ps1
Add comment 1 Plus  # Variables
Add comment 2 Plus  $powershellGetVersion = '1.5.0.0' # DO NOT use the latest 1.6.0 version as there is issues with this process
Add comment 3 Plus  # $moduleFolderPath = 'C:\Users\adamr\code\PowerShellPipeline\Staging\PSvCloud' # only target folder, NOT the .psm1 or .psd1
Add comment 4 Plus  $moduleFolderPath = "$(System.ArtifactsDirectory)\PowerShellPipeline\Artifacts\PSvCloud"
Add comment 5 Plus  $repositoryName = 'psmodules'
Add comment 6 Plus  $feedUsername = 'NotChecked'
Add comment 7 Plus  $PAT = $env:ArtifactFeedPat
Add comment 8 Plus  $packageSourceUrl = "https://adamrushuk.pkgs.visualstudio.com/_packaging/$repositoryName/nuget/v2" # Enter your VSTS AccountName (note: v2 Feed)
Add comment 9 Plus  
Add comment 10 Plus  # This is downloaded during Step 3, but could also be "C:\Users\USERNAME\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe"
Add comment 11 Plus  # if not running script as Administrator.
Add comment 12 Plus  $nugetPath = 'C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe'
Add comment 13 Plus  
Add comment 14 Plus  # Create credential
Add comment 15 Plus  $password = ConvertTo-SecureString -String $PAT -AsPlainText -Force
Add comment 16 Plus  $credential = New-Object System.Management.Automation.PSCredential ($feedUsername, $password)
Add comment 17 Plus  
Add comment 18 Plus  
Add comment 19 Plus  # Step 1
Add comment 20 Plus  # Upgrade PowerShellGet
Add comment 21 Plus  # Install-Module PowerShellGet -RequiredVersion $powershellGetVersion -Force
Add comment 22 Plus  # Remove-Module PowerShellGet -Force
Add comment 23 Plus  # Import-Module PowerShellGet -RequiredVersion $powershellGetVersion -Force
Add comment 24 Plus  
Add comment 25 Plus  
Add comment 26 Plus  # Step 2
Add comment 27 Plus  # Check NuGet is listed
Add comment 28 Plus  Get-PackageProvider -Name 'NuGet' -ForceBootstrap
Add comment 29 Plus  
Add comment 30 Plus  
Add comment 31 Plus  # Step 3
Add comment 32 Plus  # THIS WILL FAIL first time, so don't panic!
Add comment 33 Plus  # Try to Publish a PowerShell module - this will prompt and download NuGet.exe, and fail publishing the module (we publish at the end)
Add comment 34 Plus  $publishParams = @{
Add comment 35 Plus   Path = $moduleFolderPath
Add comment 36 Plus   Repository = $repositoryName
Add comment 37 Plus   NugetApiKey = 'VSTS'
Add comment 38 Plus   Force = $true
Add comment 39 Plus   Verbose = $true
Add comment 40 Plus   ErrorAction = 'SilentlyContinue'
Add comment 41 Plus  }
Add comment 42 Plus  Publish-Module @publishParams
Add comment 43 Plus  
Add comment 44 Plus  
Add comment 45 Plus  # Step 4
Add comment 46 Plus  # Register NuGet Package Source
Add comment 47 Plus  & $nugetPath Sources Add -Name $repositoryName -Source $packageSourceUrl -Username $feedUsername -Password $PAT
Add comment 48 Plus  
Add comment 49 Plus  # Check new NuGet Source is registered
Add comment 50 Plus  & $nugetPath Sources List
Add comment 51 Plus  
Add comment 52 Plus  
Add comment 53 Plus  # Step 5
Add comment 54 Plus  # Register feed
Add comment 55 Plus  $registerParams = @{
Add comment 56 Plus   Name = $repositoryName
Add comment 57 Plus   SourceLocation = $packageSourceUrl
Add comment 58 Plus   PublishLocation = $packageSourceUrl
Add comment 59 Plus   InstallationPolicy = 'Trusted'
Add comment 60 Plus   PackageManagementProvider = 'Nuget'
Add comment 61 Plus   Credential = $credential
Add comment 62 Plus   Verbose = $true
Add comment 63 Plus  }
Add comment 64 Plus  Register-PSRepository @registerParams
Add comment 65 Plus  
Add comment 66 Plus  # Check new PowerShell Repository is registered
Add comment 67 Plus  Get-PSRepository -Name $repositoryName
Add comment 68 Plus  
Add comment 69 Plus  
Add comment 70 Plus  # Step 6
Add comment 71 Plus  # Publish PowerShell module (2nd time lucky!)
Add comment 72 Plus  Publish-Module @publishParams
Add comment 73 Plus