Skip to content

PublishPowerShellModule Task

Aaron Jensen edited this page Feb 24, 2020 · 2 revisions

Overview

The PublishPowerShellModule task publishes a PowerShell module to a NuGet-based PowerShell repository (e.g. the PowerShell Gallery, ProGet, etc.). It uses the Publish-Module function from the PowerShellGet module.

You must supply the the path to the module's directory with the Path property, the name of the repository with the RepositoryName property, and the ID of the API key to use with the ApiKeyID.

If a repository named RepositoryName isn't registered, you must supply the RepositoryUri parameter so that the task can register the repository. The RepositoryUri parameter is passed to the Register-PSRepository function's PublishLocation and SourceLocation parameters.

Before publishing, the ModuleVersion property in the module manifest is updated to be the version of the current build, minus any prerelease or build metadata and the Prerelease property in the PrivateData.PSData section is updated to be the current prerelease metadata. Make sure you use prerelease metadata in the correct semver format for the repository to which you're publishing. If publishing a prerelease version, your module manifest must have a PrivateData.PSData.Prerelease property, e.g.

@{
    # snip
    PrivateData = @{
        PSData = @{
            Prerelease = '';
        }
    }
    # snip
}

Properties

  • Path (mandatory): the path to the module root, i.e. the directory where the module's ".psd1" file is.
  • RepositoryName (mandatory): the name of the PowerShell repository. If a repository by this name isn't currently registerd, the task will register it.
  • RepositoryUri: the URI to which the module should be published. This is required if the repository named RepositoryName doesn't exist. This parameter is used to register a repository if one named RepositoryName doesn't exist.
  • ApiKeyID (mandatory): the ID of the API key to use. API keys are added to your build with the Add-WhiskeyApiKey function.
  • ModuleManifestPath: the path to the module's manifest (i.e. ".psd1" file). The default is to look for a manifest with the same name as the directory given by the Path property. The task updates the module manifest with the current version and prerelease metadata.
  • CredentialID: the ID of the credential to use when registering the repository. Use Add-WhiskeyCredential in your build script to add credentials to the build. The credential is passed to the Register-PSRepository function's Credential parameter.

Examples

Example 1

Publish:
- PublishPowerShellModule:
    RepositoryName: PSGallery
    RepositoryUri: https://powershellgallery.com/api/v2/
    Path: Whiskey
    ApiKeyID: PowerShellGallery

This example demonstrates how to publish to the PowerShell Gallery. It is how Whiskey itself gets published. The PowerShellGallery is added in Whiskey's build.ps1 build script like this:

Add-WhiskeyApiKey -Context $context -ID 'PowerShellGallery' -Value $apiKey
Clone this wiki locally