Use PowerShell PSResourceGet with JFrog CLI

Register an Artifactory NuGet feed with jf setup psresource and run the PSResourceGet cmdlets with optional build-info.

Run PowerShell PSResourceGet cmdlets through JFrog CLI against a JFrog Artifactory NuGet repository. JFrog CLI registers the feed with jf setup psresource and exposes each cmdlet as its own command.

This topic covers the following tasks:

When to Use

Use these commands when PowerShell modules or scripts are stored in an Artifactory NuGet repository and the machine has PowerShell 7+ with the PSResourceGet module. JFrog CLI 2.126.0 and later include the commands. The following table lists each command and the build-info it records.

CommandNative cmdletBuild-info
jf Install-PSResourceInstall-PSResourceDirect dependencies
jf Save-PSResourceSave-PSResourceDirect dependencies
jf Update-PSResourceUpdate-PSResourceDirect dependencies, using the version resolved after the update
jf Publish-PSResourcePublish-PSResourceThe published package, with build properties stamped in Artifactory

There's no jf psresource command and no jf psresource-config command. The cmdlets always run natively. You don't set JFROG_RUN_NATIVE.

PSResourceGet uses a NuGet v3 feed. Artifactory doesn't have a separate PowerShell package type. The PowerShellGet commands Install-Module and Publish-Module are a different client. For those commands without JFrog CLI, see NuGet Repositories — PowerShell Client.

📘

Note

Package Alias doesn't intercept Install-PSResource, Save-PSResource, Update-PSResource, or Publish-PSResource. Run the jf commands on this page. For more information, see Use JFrog CLI Package Alias.

Prerequisites

  • JFrog CLI 2.126.0 or later. Verify with jf --version.
  • PowerShell 7 or later, available as pwsh, with the Microsoft.PowerShell.PSResourceGet module installed. On Windows, JFrog CLI uses powershell.exe only when pwsh isn't on PATH and that Windows PowerShell installation has the module. The commands run on macOS, Linux, and Windows.
  • A JFrog CLI server configured with jf config add.
  • An Artifactory NuGet repository, virtual, local, or remote. Install, save, and update need read permission. Publish needs write permission.

Verify the module:

pwsh -NoProfile -Command "Get-Module -ListAvailable -Name Microsoft.PowerShell.PSResourceGet"

Configure PSResourceGet for Artifactory

jf setup psresource registers one trusted PSResourceGet repository for an Artifactory NuGet v3 feed. The repository name is jfrt-<hostname>-<repository-key>. Setup stores the registration in the current user's PSResourceRepository.xml, not in a machine-wide file. Run setup again for each user account.

Setup doesn't store credentials in that file. jf Install-PSResource, jf Save-PSResource, jf Update-PSResource, and jf Publish-PSResource inject -Credential for the command when you pass --repo-resolve or --repo.

To configure PSResourceGet for Artifactory:

  1. Run jf setup psresource.
jf setup psresource --server-id=<SERVER_ID> --repo=<REPOSITORY_KEY> --project=<PROJECT_KEY>

Where:

  • <SERVER_ID>: JFrog CLI server ID from jf config add. Omit --server-id to use the default server.
  • <REPOSITORY_KEY>: NuGet repository key. Omit --repo to choose the repository interactively.
  • <PROJECT_KEY>: JFrog Project key, when the repository belongs to a project. Omit --project when the repository isn't in a project.

For example:

jf setup psresource --server-id=my-server --repo=nuget-virtual

On success, the command prints the repository name:

PSResource source name: jfrt-acme.jfrog.io-nuget-virtual
  1. Use that printed name as the native -Repository value on later PSResourceGet commands.

Re-running setup for the same name replaces that registration and leaves other PSResourceGet repositories in place.


Install, Save, and Update Modules

JFrog CLI forwards native parameters such as -Name, -Version, -Repository, -Scope, and -Path unchanged. --repo-resolve records the Artifactory repository on the build-info and supplies credentials. It doesn't select the PSResourceGet repository. Pass -Repository for that.

To install, save, or update a module:

  1. Install a module.
jf Install-PSResource -Name <MODULE_NAME> -Repository <SOURCE_NAME> --repo-resolve=<REPOSITORY_KEY> --server-id=<SERVER_ID> --build-name=<BUILD_NAME> --build-number=<BUILD_NUMBER>

Where:

  • <MODULE_NAME>: PowerShell module name.
  • <SOURCE_NAME>: PSResourceGet repository name printed by jf setup psresource.
  • <REPOSITORY_KEY>: Artifactory NuGet repository key recorded on the build-info.
  • <SERVER_ID>: JFrog CLI server ID. Omit --server-id to use the default server.
  • <BUILD_NAME>: Build name. Required with <BUILD_NUMBER>.
  • <BUILD_NUMBER>: Build number. Required with <BUILD_NAME>.

For example:

jf Install-PSResource -Name MyModule -Repository jfrt-acme.jfrog.io-nuget-virtual --repo-resolve=nuget-virtual --server-id=my-server --build-name=app --build-number=1
  1. Save a module to a local path.
jf Save-PSResource -Name <MODULE_NAME> -Path <LOCAL_PATH> -Repository <SOURCE_NAME> --repo-resolve=<REPOSITORY_KEY> --build-name=<BUILD_NAME> --build-number=<BUILD_NUMBER>

Where:

  • <LOCAL_PATH>: Directory where PSResourceGet writes the module.

For example:

jf Save-PSResource -Name MyModule -Path ./local-modules -Repository jfrt-acme.jfrog.io-nuget-virtual --repo-resolve=nuget-virtual --build-name=app --build-number=1
  1. Update a module.
jf Update-PSResource -Name <MODULE_NAME> -Repository <SOURCE_NAME> --repo-resolve=<REPOSITORY_KEY> --build-name=<BUILD_NAME> --build-number=<BUILD_NUMBER>

For example:

jf Update-PSResource -Name MyModule -Repository jfrt-acme.jfrog.io-nuget-virtual --repo-resolve=nuget-virtual --build-name=app --build-number=1
  1. Publish the collected build-info.
jf rt build-publish <BUILD_NAME> <BUILD_NUMBER>

For example:

jf rt build-publish app 1

You can also pass the following options.

OptionDescription
--moduleModule name inside the build-info. Requires both build flags.
--projectJFrog Project key stored on the build-info.
📘

Note

PSResourceGet has no lock file, so build-info lists the modules named on the command. JFrog CLI doesn't record transitive dependencies. JFrog CLI reads checksums with a HEAD request to Artifactory. jf Save-PSResource -Path is the exception. JFrog CLI computes those checksums from the .nupkg written to that path.


Publish a Module

Publish-PSResource builds the .nupkg in memory and uploads it. JFrog CLI doesn't read a local .nupkg for checksums. It confirms the artifact in Artifactory and stamps build properties when both build flags are set.

--repo is the deployment repository recorded on the build-info and the repository whose credentials are injected. It must be the same Artifactory repository that -Repository resolves to. --repo doesn't replace -Repository.

To publish a module:

  1. Run jf Publish-PSResource.
jf Publish-PSResource -Path <MODULE_PATH> -Repository <SOURCE_NAME> --repo=<REPOSITORY_KEY> --server-id=<SERVER_ID> --build-name=<BUILD_NAME> --build-number=<BUILD_NUMBER>

Where:

  • <MODULE_PATH>: Path to the module to publish.
  • <SOURCE_NAME>: PSResourceGet repository name printed by jf setup psresource.
  • <REPOSITORY_KEY>: Artifactory NuGet repository key. This must be the repository that <SOURCE_NAME> uploads to.
  • <SERVER_ID>: JFrog CLI server ID. Omit --server-id to use the default server.
  • <BUILD_NAME>: Build name. Required with <BUILD_NUMBER>.
  • <BUILD_NUMBER>: Build number. Required with <BUILD_NAME>.

For example:

jf Publish-PSResource -Path ./MyModule -Repository jfrt-acme.jfrog.io-nuget-local --repo=nuget-local --server-id=my-server --build-name=app --build-number=1
  1. Publish the collected build-info.
jf rt build-publish <BUILD_NAME> <BUILD_NUMBER>

For example:

jf rt build-publish app 1

Passing only --build-name or only --build-number is an error, and the cmdlet doesn't run.


Troubleshooting

The following table lists common failures and how to fix them.

SymptomCauseFix
'jf Install-PSResource'/'jf Publish-PSResource' requires PowerShell 7+pwsh is missing, or Microsoft.PowerShell.PSResourceGet isn't installedInstall PowerShell 7 or later and the PSResourceGet module, then rerun the command
The cmdlet resolves from a different repository than the build-info-Repository and --repo-resolve don't refer to the same Artifactory repositoryPass the jfrt-... name from setup to -Repository, and pass that repository key to --repo-resolve
401 from Artifactory--repo-resolve or --repo was omitted, so no credential was injected, or the token cannot access the repositoryPass the matching repository option and confirm the server configuration with jf config show
Publish properties are missing--repo doesn't match the repository -Repository uploads toUse the same Artifactory repository for both
Setup works for one user and not anotherRegistration is per user profileRun jf setup psresource as that user

To enable debug logging, run export JFROG_CLI_LOG_LEVEL=DEBUG, then rerun the command. In PowerShell, use $env:JFROG_CLI_LOG_LEVEL = "DEBUG".


Frequently Asked Questions

This section provides answers to frequently asked questions about PSResourceGet and JFrog CLI.

plusFAQs
Q: Is this the same as Install-Module?

A: No. These commands wrap PSResourceGet (Install-PSResource and the related cmdlets). Install-Module and Publish-Module belong to PowerShellGet. See NuGet Repositories — PowerShell Client for that client.

Q: Does jf setup psresource save my token in PSResourceRepository.xml?

A: No. Setup registers the feed as a trusted repository and doesn't persist credentials. The jf cmdlets inject -Credential for that invocation when you pass --repo-resolve or --repo. For more information, see Configure PSResourceGet for Artifactory.

Q: When do I set JFROG_RUN_NATIVE?

A: No. These commands always run the native PSResourceGet cmdlet.

Related Topics


Did this page help you?