Publishing your powershell nuget module to your Azure DevOps Artifacts
Log into your Azure DevOps Project
Click Artifacts
Create Feed
Give it a name, visibility, and Scope
After your feed is created, click Connect to feed and click NuGet to get the package source (you can get this from any type). It'll look like this:
https://pkgs.dev.azure.com/ORG/PROJECT/_packaging/FEED/nuget/v3/index.json
Click on your settings icon and select Personal Access Tokens
Create a new token and give it at least
- Work Items (Read)
- Packaging (Read & Write)
Save this token for later use.
Create a new working directory for your module
mkdir c:\mud
Go into this directory.
Create a new manifest file here.
New-ModuleManifest -Path .\mud.psd1
Create a new module root file.
New-item .\mud.psm1
Update the new manifest file with at least following
RootModule = 'mud.psm1' ModuleVersion = '1.1.0' FunctionsToExport = @('function1','function2') FileList = @('file1.ps1','file2.ps1')
- Functions are list of functions that you want exposed from this module.
- Files are list of files that will be consumed by this module. These files must reside at the root of this folder.
Create a nuget spec file using the name of your module (be sure you have downloaded nuget cli)
nuget spec mud
Go into this new file (mud.nuspec)
- Be sure the version matches (with mud.psd1)
- Be sure to update ProjectURL and IconURL or just remove it altogether
- Remove the default dependency
Package your module
nuget pack mud.nuspec
Add the source
nuget sources Add -Name "myfeed" -Source $source_push -username $username -password $pat
- source_push is your package source address from above
- username is probably your email address
- pat is your Personal Access Token you got earlier
Push this package
nuget push -Source "myfeed" -ApiKey AzureDevOpsServices .\mud.nupkg
That's it. Now you can browse, find, and install the above module.
> Register-PSRepository -Name $repo_name -SourceLocation $source_repo -InstallationPolicy Trusted > Get-PSRepository > find-module -Repository $repo_name -credential $credsAzureDevopsServices > Install-Module -Name $module_name -Repository $repo_name -credential $credsAzureDevopsServices
No comments:
Post a Comment