Tuesday, September 22, 2020

Using Pipeline to Publish your powershell nuget module

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


Update the targetFiles to '**/*.psd1' and click Add. The resulting new Task
taskreplacetokens@3
  displayName'Replace Version Token'
  inputs:
    targetFiles'**/*.psd1'
    encoding'auto'
    writeBOMtrue
    actionOnMissing'warn'
    keepTokenfalse
    tokenPrefix'#{'
    tokenSuffix'}#'
    useLegacyPatternfalse
    enableTelemetryfalse

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:

taskNuGetCommand@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):

taskNuGetCommand@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:

taskPublishBuildArtifacts@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

AWS WAF log4j query

How to query AWS WAF log for log4j attacks 1. Setup your Athena table using this instruction https://docs.aws.amazon.com/athena/latest/ug/wa...