Using Pipeline to Publish your powershell nuget module
Create a new Repo
Bring over all the files from previous instruction on Publishing your Powershell Nuget Module.
Update Manifest file (this is to allow the pipeline to update the version for us):
ModuleVersion = '#{MODULEVERSION}#'
Go to Pipelines, Click New Pipeline
Select Azure Repos Git
Select Starter Pipeline
Clear content
Paste this
name: '$(BuildDefinitionName)_$(Build.BuildId)' trigger: branches: include: - master variables: major: '1' minor: '0' revision: $[counter(variables['minor'], 1)] MODULEVERSION: '$(major).$(minor).$(revision)'
In the assistant pane, search for Replace Tokens
- task: replacetokens@3
displayName: 'Replace Version Token'
inputs:
targetFiles: '**/*.psd1'
encoding: 'auto'
writeBOM: true
actionOnMissing: 'warn'
keepToken: false
tokenPrefix: '#{'
tokenSuffix: '}#'
useLegacyPattern: false
enableTelemetry: false
In the assistant pane, search for Nuget (just regular Nuget) and enter as follows.
- Command: pack
- Path: **/*.nuspec
- Automatic package versioning: Use an environment variable
- Environment variable: MODULEVERSION
- Additional build properties: MODULEVERSION=$(MODULEVERSION)
The resulting task:
- task: NuGetCommand@2
displayName: 'NuGet Pack'
inputs:
command: 'pack'
packagesToPack: '**/*.nuspec'
versioningScheme: 'byEnvVar'
versionEnvVar: 'MODULEVERSION'
buildProperties: 'MODULEVERSION=$(MODULEVERSION)'
Back to assistant pane, search again for Nuget
- Command: push
- Target Feed: Point to your own feed
The resulting task (your feed ID will be unique to you):
- task: NuGetCommand@2
displayName: 'NuGet Push'
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: '00000000-0000-0000-0000-000000000000'
Back to assistant pane, search for Publish Build Artifacts
- Artifact Name: NugetPackage
- Artifact Publish Location: Azure Pipeline
The resulting task:
- task: PublishBuildArtifacts@1
displayName: 'Publish Build Artifacts'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'NuGetPackage'
publishLocation: 'Container'
That's it!
Save and run it.
No comments:
Post a Comment